@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
@@ -0,0 +1,167 @@
1
+ import {
2
+ PROTOCOL_V2_BLE_FILE_CHUNK_SIZE,
3
+ PROTOCOL_V2_WEBUSB_FILE_CHUNK_SIZE,
4
+ } from '@onekeyfe/hd-transport';
5
+ import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
6
+
7
+ import { BaseMethod } from './BaseMethod';
8
+ import {
9
+ validateNonEmptyString,
10
+ validateNonNegativeInteger,
11
+ validateOptionalNonNegativeInteger,
12
+ validateOptionalPercentage,
13
+ } from './helpers/filesystemValidation';
14
+ import { hexToBytes, isHexString, stripHexPrefix } from './helpers/hexUtils';
15
+ import { DataManager } from '../data-manager';
16
+
17
+ export type FileReadParams = {
18
+ path: string;
19
+ offset?: number;
20
+ totalSize?: number;
21
+ chunkLen?: number;
22
+ uiPercentage?: number;
23
+ };
24
+
25
+ const MIN_FILE_READ_CHUNK_SIZE = 64;
26
+
27
+ function getProtocolV2FileReadChunkLimit() {
28
+ const env = DataManager.getSettings('env');
29
+ if (env && DataManager.isBleConnect(env)) {
30
+ return PROTOCOL_V2_BLE_FILE_CHUNK_SIZE;
31
+ }
32
+ return PROTOCOL_V2_WEBUSB_FILE_CHUNK_SIZE;
33
+ }
34
+
35
+ function normalizeChunkSize(value: unknown, maxChunkSize: number): number {
36
+ const numeric = Number(value);
37
+ if (!Number.isFinite(numeric) || numeric <= 0) return maxChunkSize;
38
+ return Math.min(Math.max(Math.floor(numeric), MIN_FILE_READ_CHUNK_SIZE), maxChunkSize);
39
+ }
40
+
41
+ function toFiniteNumber(value: unknown): number | undefined {
42
+ if (typeof value === 'number' && Number.isFinite(value)) return value;
43
+ if (typeof value === 'string') {
44
+ const numeric = Number(value);
45
+ return Number.isFinite(numeric) ? numeric : undefined;
46
+ }
47
+ if (value && typeof value === 'object') {
48
+ const longLike = value as { toNumber?: () => number };
49
+ if (typeof longLike.toNumber === 'function') {
50
+ const numeric = longLike.toNumber();
51
+ return Number.isFinite(numeric) ? numeric : undefined;
52
+ }
53
+ }
54
+ return undefined;
55
+ }
56
+
57
+ function toUint8Array(value: unknown): Uint8Array {
58
+ if (value instanceof Uint8Array) return value;
59
+ if (value instanceof ArrayBuffer) return new Uint8Array(value);
60
+ if (ArrayBuffer.isView(value)) {
61
+ return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
62
+ }
63
+ if (typeof value === 'string') {
64
+ const hex = stripHexPrefix(value);
65
+ if (!hex) return new Uint8Array(0);
66
+ if (!isHexString(hex) || hex.length % 2 !== 0) return new Uint8Array(0);
67
+ return hexToBytes(hex);
68
+ }
69
+ return new Uint8Array(0);
70
+ }
71
+
72
+ export default class FileRead extends BaseMethod<FileReadParams> {
73
+ init() {
74
+ // Protocol V2 (Pro2) 专属方法,core 调度层统一做非 V2 设备守卫
75
+ this.requireProtocolV2 = true;
76
+ this.skipForceUpdateCheck = true;
77
+ this.useDevicePassphraseState = false;
78
+ const path = validateNonEmptyString(this.payload.path, 'path');
79
+ this.params = {
80
+ path,
81
+ offset: validateNonNegativeInteger(this.payload.offset, 'offset', 0),
82
+ totalSize: validateNonNegativeInteger(this.payload.totalSize, 'totalSize', 0),
83
+ chunkLen: validateOptionalNonNegativeInteger(this.payload.chunkLen, 'chunkLen'),
84
+ uiPercentage: validateOptionalPercentage(this.payload.uiPercentage, 'uiPercentage'),
85
+ };
86
+ }
87
+
88
+ async run() {
89
+ const startOffset = this.params.offset ?? 0;
90
+ const requestedLength = Number(this.params.totalSize);
91
+ const chunkSize = normalizeChunkSize(this.params.chunkLen, getProtocolV2FileReadChunkLimit());
92
+ let totalLength = Number.isFinite(requestedLength) && requestedLength > 0 ? requestedLength : 0;
93
+
94
+ if (totalLength === 0) {
95
+ const pathInfoRes = await this.device.commands.typedCall(
96
+ 'FilesystemPathInfoQuery',
97
+ 'FilesystemPathInfo',
98
+ {
99
+ path: this.params.path,
100
+ }
101
+ );
102
+ const fileSize = toFiniteNumber(pathInfoRes.message?.size);
103
+ if (!pathInfoRes.message?.exist || pathInfoRes.message?.directory) {
104
+ throw ERRORS.TypedError(
105
+ HardwareErrorCode.RuntimeError,
106
+ `FilesystemFileRead path is not a file: ${this.params.path}`
107
+ );
108
+ }
109
+ if (fileSize === undefined || fileSize < startOffset) {
110
+ throw ERRORS.TypedError(
111
+ HardwareErrorCode.RuntimeError,
112
+ `FilesystemFileRead invalid offset ${startOffset} for ${this.params.path}`
113
+ );
114
+ }
115
+ totalLength = fileSize - startOffset;
116
+ }
117
+
118
+ const chunks: Uint8Array[] = [];
119
+ let read = 0;
120
+ let lastMessage: Record<string, unknown> | undefined;
121
+
122
+ while (read < totalLength) {
123
+ const readLen = Math.min(chunkSize, totalLength - read);
124
+ const offset = startOffset + read;
125
+ const progress =
126
+ this.params.uiPercentage ??
127
+ Math.min(Math.ceil(((read + readLen) / Math.max(totalLength, 1)) * 100), 99);
128
+ const res = await this.device.commands.typedCall('FilesystemFileRead', 'FilesystemFile', {
129
+ file: {
130
+ path: this.params.path,
131
+ offset,
132
+ total_size: 0,
133
+ },
134
+ chunk_len: readLen,
135
+ ui_percentage: progress,
136
+ });
137
+ const data = toUint8Array(res.message?.data);
138
+ lastMessage = res.message;
139
+
140
+ if (data.byteLength === 0) {
141
+ throw ERRORS.TypedError(
142
+ HardwareErrorCode.RuntimeError,
143
+ `FilesystemFileRead received empty data at offset ${offset}`
144
+ );
145
+ }
146
+
147
+ chunks.push(data);
148
+ read += data.byteLength;
149
+ }
150
+
151
+ const combined = new Uint8Array(read);
152
+ let cursor = 0;
153
+ chunks.forEach(chunk => {
154
+ combined.set(chunk, cursor);
155
+ cursor += chunk.byteLength;
156
+ });
157
+
158
+ return Promise.resolve({
159
+ ...lastMessage,
160
+ path: this.params.path,
161
+ offset: startOffset,
162
+ total_size: totalLength,
163
+ data: combined,
164
+ chunks: chunks.length,
165
+ });
166
+ }
167
+ }
@@ -0,0 +1,216 @@
1
+ import {
2
+ PROTOCOL_V2_BLE_FILE_CHUNK_SIZE,
3
+ PROTOCOL_V2_WEBUSB_FILE_CHUNK_SIZE,
4
+ } from '@onekeyfe/hd-transport';
5
+ import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
6
+
7
+ import { BaseMethod } from './BaseMethod';
8
+ import {
9
+ validateNonEmptyString,
10
+ validateNonNegativeInteger,
11
+ validateOptionalNonNegativeInteger,
12
+ validateOptionalPercentage,
13
+ validateRequiredData,
14
+ } from './helpers/filesystemValidation';
15
+ import { UI_REQUEST, createUiMessage } from '../events/ui-request';
16
+ import { DataManager } from '../data-manager';
17
+
18
+ export type FileWriteParams = {
19
+ path: string;
20
+ offset?: number;
21
+ totalSize?: number;
22
+ data: ArrayBuffer | Uint8Array | Blob | string;
23
+ chunkSize?: number;
24
+ chunkLen?: number;
25
+ overwrite?: boolean;
26
+ append?: boolean;
27
+ uiPercentage?: number;
28
+ timeoutMs?: number | string;
29
+ };
30
+
31
+ const MIN_FILE_CHUNK_SIZE = 64;
32
+
33
+ function getProtocolV2FileChunkLimit() {
34
+ const env = DataManager.getSettings('env');
35
+ if (env && DataManager.isBleConnect(env)) {
36
+ return PROTOCOL_V2_BLE_FILE_CHUNK_SIZE;
37
+ }
38
+ return PROTOCOL_V2_WEBUSB_FILE_CHUNK_SIZE;
39
+ }
40
+
41
+ async function dataToUint8Array(data: FileWriteParams['data'] | Blob): Promise<Uint8Array> {
42
+ if (typeof data === 'string') {
43
+ return new TextEncoder().encode(data);
44
+ }
45
+
46
+ if (data instanceof ArrayBuffer) {
47
+ return new Uint8Array(data);
48
+ }
49
+
50
+ if (ArrayBuffer.isView(data)) {
51
+ return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
52
+ }
53
+
54
+ if (typeof Blob !== 'undefined' && data instanceof Blob) {
55
+ return new Uint8Array(await data.arrayBuffer());
56
+ }
57
+
58
+ throw ERRORS.TypedError(
59
+ HardwareErrorCode.CallMethodInvalidParameter,
60
+ 'Unsupported FilesystemFileWrite data'
61
+ );
62
+ }
63
+
64
+ function normalizeChunkSize(value: unknown, maxChunkSize: number): number {
65
+ const numeric = Number(value);
66
+ if (!Number.isFinite(numeric) || numeric <= 0) return maxChunkSize;
67
+ return Math.min(Math.max(Math.floor(numeric), MIN_FILE_CHUNK_SIZE), maxChunkSize);
68
+ }
69
+
70
+ function getConfirmedProgress(
71
+ processedByte: number,
72
+ totalSize: number,
73
+ written: number,
74
+ dataLength: number
75
+ ) {
76
+ if (Number.isFinite(processedByte) && Number.isFinite(totalSize) && totalSize > 0) {
77
+ if (processedByte >= totalSize) return 100;
78
+ return Math.min(Math.max(Math.floor((processedByte / totalSize) * 100), 0), 99);
79
+ }
80
+ if (dataLength > 0) {
81
+ if (written >= dataLength) return 100;
82
+ return Math.min(Math.max(Math.floor((written / dataLength) * 100), 0), 99);
83
+ }
84
+ return 100;
85
+ }
86
+
87
+ export default class FileWrite extends BaseMethod<FileWriteParams> {
88
+ init() {
89
+ // Protocol V2 (Pro2) 专属方法,core 调度层统一做非 V2 设备守卫
90
+ this.requireProtocolV2 = true;
91
+ this.skipForceUpdateCheck = true;
92
+ this.useDevicePassphraseState = false;
93
+ validateRequiredData(this.payload.data, 'data');
94
+ const path = validateNonEmptyString(this.payload.path, 'path');
95
+ const offset = validateNonNegativeInteger(this.payload.offset, 'offset', 0);
96
+ this.params = {
97
+ path,
98
+ offset,
99
+ totalSize: validateNonNegativeInteger(this.payload.totalSize, 'totalSize', 0),
100
+ data: this.payload.data,
101
+ chunkSize: validateOptionalNonNegativeInteger(this.payload.chunkSize, 'chunkSize'),
102
+ chunkLen: validateOptionalNonNegativeInteger(this.payload.chunkLen, 'chunkLen'),
103
+ overwrite: this.payload.overwrite ?? offset === 0,
104
+ append: this.payload.append ?? false,
105
+ uiPercentage: validateOptionalPercentage(this.payload.uiPercentage, 'uiPercentage'),
106
+ timeoutMs: validateOptionalNonNegativeInteger(this.payload.timeoutMs, 'timeoutMs'),
107
+ };
108
+ }
109
+
110
+ async run() {
111
+ const data = await dataToUint8Array(this.params.data);
112
+ const dataLength = data.byteLength;
113
+ const offsetValue = Number(this.params.offset ?? 0);
114
+ const startOffset = Number.isFinite(offsetValue) && offsetValue > 0 ? offsetValue : 0;
115
+ const payloadTotalSize = Number(this.params.totalSize);
116
+ const totalSize =
117
+ Number.isFinite(payloadTotalSize) && payloadTotalSize > 0
118
+ ? payloadTotalSize
119
+ : startOffset + dataLength;
120
+
121
+ if (totalSize < startOffset + dataLength) {
122
+ throw ERRORS.TypedError(
123
+ HardwareErrorCode.RuntimeError,
124
+ `FilesystemFileWrite totalSize ${totalSize} is smaller than offset + data length ${
125
+ startOffset + dataLength
126
+ }`
127
+ );
128
+ }
129
+
130
+ const chunkSize = normalizeChunkSize(
131
+ this.params.chunkSize ?? this.params.chunkLen,
132
+ getProtocolV2FileChunkLimit()
133
+ );
134
+ const overwrite = this.params.overwrite ?? false;
135
+ const append = this.params.append ?? false;
136
+ let written = 0;
137
+ let chunkIndex = 0;
138
+ let lastMessage: Record<string, unknown> | undefined;
139
+ const startTime = Date.now();
140
+ const timeoutMs =
141
+ this.params.timeoutMs === undefined ? undefined : Number(this.params.timeoutMs);
142
+
143
+ while (written < dataLength) {
144
+ const chunkEnd = Math.min(written + chunkSize, dataLength);
145
+ const chunk = data.slice(written, chunkEnd);
146
+ const offset = startOffset + written;
147
+ const isFirstChunk = chunkIndex === 0;
148
+ const progress =
149
+ this.params.uiPercentage ??
150
+ Math.min(Math.ceil(((written + chunk.byteLength) / dataLength) * 100), 99);
151
+
152
+ const res = await this.device.commands.typedCall(
153
+ 'FilesystemFileWrite',
154
+ 'FilesystemFile',
155
+ {
156
+ file: {
157
+ path: this.params.path,
158
+ offset,
159
+ total_size: totalSize,
160
+ data: chunk,
161
+ },
162
+ overwrite: isFirstChunk ? overwrite : false,
163
+ append,
164
+ ui_percentage: progress,
165
+ },
166
+ {
167
+ timeoutMs,
168
+ }
169
+ );
170
+
171
+ lastMessage = res.message;
172
+ const processedByte = Number(res.message?.processed_byte);
173
+ if (Number.isFinite(processedByte) && processedByte > offset) {
174
+ written = processedByte - startOffset;
175
+ } else {
176
+ written += chunk.byteLength;
177
+ }
178
+
179
+ if (written > dataLength) {
180
+ throw ERRORS.TypedError(
181
+ HardwareErrorCode.RuntimeError,
182
+ `FilesystemFileWrite invalid processed_byte ${processedByte}`
183
+ );
184
+ }
185
+
186
+ const confirmedProcessedByte =
187
+ Number.isFinite(processedByte) && processedByte > offset
188
+ ? processedByte
189
+ : startOffset + written;
190
+ if (typeof this.postMessage === 'function') {
191
+ const elapsedMs = Date.now() - startTime;
192
+ const transferredBytes = Math.min(written, dataLength);
193
+ this.postMessage(
194
+ createUiMessage(UI_REQUEST.DEVICE_PROGRESS, {
195
+ progress: getConfirmedProgress(confirmedProcessedByte, totalSize, written, dataLength),
196
+ transferredBytes,
197
+ totalBytes: dataLength,
198
+ rateBytesPerSecond:
199
+ elapsedMs > 0 ? Math.round((transferredBytes / elapsedMs) * 1000) : undefined,
200
+ elapsedMs,
201
+ })
202
+ );
203
+ }
204
+ chunkIndex += 1;
205
+ }
206
+
207
+ return Promise.resolve({
208
+ ...lastMessage,
209
+ path: this.params.path,
210
+ offset: startOffset,
211
+ total_size: totalSize,
212
+ processed_byte: startOffset + written,
213
+ chunks: chunkIndex,
214
+ });
215
+ }
216
+ }
@@ -14,7 +14,7 @@ import { uploadFirmware } from './firmware/uploadFirmware';
14
14
  import { createUiMessage } from '../events';
15
15
  import { DeviceModelToTypes, type KnownDevice } from '../types';
16
16
  import { isEnteredManuallyBoot } from './firmware/bootloaderHelper';
17
- import { LoggerNames, getDeviceType, getDeviceUUID, getLogger, wait } from '../utils';
17
+ import { LoggerNames, getDeviceUUID, getLogger, wait } from '../utils';
18
18
  import { DataManager } from '../data-manager';
19
19
  import { DevicePool } from '../device/DevicePool';
20
20
 
@@ -92,7 +92,7 @@ export default class FirmwareUpdate extends BaseMethod<Params> {
92
92
  true
93
93
  );
94
94
  await this.device.initialize();
95
- if (this.device.features?.bootloader_mode) {
95
+ if (this.device.isBootloader()) {
96
96
  clearInterval(intervalTimer);
97
97
  this.checkPromise?.resolve(true);
98
98
  }
@@ -105,7 +105,7 @@ export default class FirmwareUpdate extends BaseMethod<Params> {
105
105
  const devicesDescriptor = deviceDiff?.descriptors ?? [];
106
106
  const { deviceList } = await DevicePool.getDevices(devicesDescriptor, connectId);
107
107
 
108
- if (deviceList.length === 1 && deviceList[0]?.features?.bootloader_mode) {
108
+ if (deviceList.length === 1 && deviceList[0]?.isBootloader()) {
109
109
  // should update current device from cache
110
110
  // because device was reboot and had some new requests
111
111
  this.device.updateFromCache(deviceList[0]);
@@ -131,9 +131,17 @@ export default class FirmwareUpdate extends BaseMethod<Params> {
131
131
  async run() {
132
132
  const { device, params } = this;
133
133
  const { features, commands } = device;
134
- const deviceType = getDeviceType(features);
134
+ const deviceType = device.getCurrentDeviceType();
135
+
136
+ // Protocol V2 (Pro2) 固件升级走 DeviceFirmwareUpdate 流程,禁止进入 legacy 入口
137
+ if (device.isProtocolV2()) {
138
+ throw ERRORS.TypedError(
139
+ HardwareErrorCode.RuntimeError,
140
+ 'Protocol V2 firmware update must use firmwareUpdateV4'
141
+ );
142
+ }
135
143
 
136
- if (!features?.bootloader_mode && features) {
144
+ if (!device.isBootloader() && features) {
137
145
  const uuid = getDeviceUUID(features);
138
146
  // should go to bootloader mode manually
139
147
  if (isEnteredManuallyBoot(features, params.updateType)) {
@@ -17,10 +17,9 @@ import { getBinary, getInfo, getSysResourceBinary } from './firmware/getBinary';
17
17
  import { updateResources, uploadFirmware } from './firmware/uploadFirmware';
18
18
  import {
19
19
  LoggerNames,
20
+ getDeviceBootloaderVersion,
20
21
  getDeviceFirmwareVersion,
21
- getDeviceType,
22
22
  getDeviceUUID,
23
- getFirmwareType,
24
23
  getLogger,
25
24
  wait,
26
25
  } from '../utils';
@@ -30,7 +29,6 @@ import { DataManager } from '../data-manager';
30
29
  import { DEVICE } from '../events';
31
30
 
32
31
  import type { Features, KnownDevice } from '../types';
33
- import type { Device } from '../device/Device';
34
32
 
35
33
  type Params = {
36
34
  binary?: ArrayBuffer;
@@ -102,7 +100,7 @@ export default class FirmwareUpdateV2 extends BaseMethod<Params> {
102
100
  );
103
101
  };
104
102
 
105
- private async _promptDeviceInBootloaderForWebDevice({ device }: { device: Device }) {
103
+ private async _promptDeviceInBootloaderForWebDevice() {
106
104
  return new Promise((resolve, reject) => {
107
105
  if (this.device.listenerCount(DEVICE.SELECT_DEVICE_IN_BOOTLOADER_FOR_WEB_DEVICE) > 0) {
108
106
  this.device.emit(
@@ -133,9 +131,8 @@ export default class FirmwareUpdateV2 extends BaseMethod<Params> {
133
131
  // eslint-disable-next-line prefer-const
134
132
  let timeoutTimer: ReturnType<typeof setTimeout> | undefined;
135
133
 
136
- const isTouchOrProDevice =
137
- getDeviceType(this?.device?.features) === EDeviceType.Touch ||
138
- getDeviceType(this?.device?.features) === EDeviceType.Pro;
134
+ const deviceType = this.device?.getCurrentDeviceType();
135
+ const isTouchOrProDevice = deviceType === EDeviceType.Touch || deviceType === EDeviceType.Pro;
139
136
 
140
137
  const intervalTimer: ReturnType<typeof setInterval> | undefined = setInterval(
141
138
  async () => {
@@ -157,9 +154,7 @@ export default class FirmwareUpdateV2 extends BaseMethod<Params> {
157
154
 
158
155
  try {
159
156
  this.postTipMessage(FirmwareUpdateTipMessage.SelectDeviceInBootloaderForWebDevice);
160
- const confirmed = await this._promptDeviceInBootloaderForWebDevice({
161
- device: this.device,
162
- });
157
+ const confirmed = await this._promptDeviceInBootloaderForWebDevice();
163
158
  if (confirmed) {
164
159
  await this._checkDeviceInBootloaderMode(connectId, intervalTimer, timeoutTimer);
165
160
  }
@@ -181,7 +176,7 @@ export default class FirmwareUpdateV2 extends BaseMethod<Params> {
181
176
  true
182
177
  );
183
178
  await this.device.initialize();
184
- if (this.device.features?.bootloader_mode) {
179
+ if (this.device.isBootloader()) {
185
180
  clearInterval(intervalTimer);
186
181
  this.checkPromise?.resolve(true);
187
182
  }
@@ -214,7 +209,7 @@ export default class FirmwareUpdateV2 extends BaseMethod<Params> {
214
209
  const devicesDescriptor = deviceDiff?.descriptors ?? [];
215
210
  const { deviceList } = await DevicePool.getDevices(devicesDescriptor, connectId);
216
211
 
217
- if (deviceList.length === 1 && deviceList[0]?.features?.bootloader_mode) {
212
+ if (deviceList.length === 1 && deviceList[0]?.isBootloader()) {
218
213
  // should update current device from cache
219
214
  // because device was reboot and had some new requests
220
215
  this.device.updateFromCache(deviceList[0]);
@@ -229,19 +224,19 @@ export default class FirmwareUpdateV2 extends BaseMethod<Params> {
229
224
  }
230
225
 
231
226
  isEnteredManuallyBoot(features: Features) {
232
- const deviceType = getDeviceType(features);
227
+ const deviceType = this.device.getCurrentDeviceType();
233
228
  const isMini = deviceType === EDeviceType.Mini;
234
229
  const isBoot183ClassicUpBle =
235
230
  this.params.updateType === 'firmware' &&
236
231
  deviceType === EDeviceType.Classic &&
237
- features.bootloader_version === '1.8.3';
232
+ getDeviceBootloaderVersion(features).join('.') === '1.8.3';
238
233
  return isMini || isBoot183ClassicUpBle;
239
234
  }
240
235
 
241
236
  isSupportResourceUpdate(features: Features, updateType: string) {
242
237
  if (updateType !== 'firmware') return false;
243
238
 
244
- const deviceType = getDeviceType(features);
239
+ const deviceType = this.device.getCurrentDeviceType();
245
240
  const isTouchMode = deviceType === EDeviceType.Touch || deviceType === EDeviceType.Pro;
246
241
  const currentVersion = getDeviceFirmwareVersion(features).join('.');
247
242
 
@@ -254,7 +249,7 @@ export default class FirmwareUpdateV2 extends BaseMethod<Params> {
254
249
  */
255
250
  checkVersionForCopyTouchResource(features: Features | undefined, firmwareType: EFirmwareType) {
256
251
  if (!features) return;
257
- const deviceType = getDeviceType(features);
252
+ const deviceType = this.device.getCurrentDeviceType();
258
253
  const currentVersion = getDeviceFirmwareVersion(features).join('.');
259
254
  const targetVersion = this.params.version?.join('.');
260
255
  const { updateType } = this.params;
@@ -279,14 +274,22 @@ export default class FirmwareUpdateV2 extends BaseMethod<Params> {
279
274
  async run() {
280
275
  const { device, params } = this;
281
276
  const { features, commands } = device;
282
- const deviceType = getDeviceType(features);
277
+ const deviceType = device.getCurrentDeviceType();
283
278
 
284
- const deviceFirmwareType = getFirmwareType(device.features);
279
+ // Protocol V2 (Pro2) 固件升级走 DeviceFirmwareUpdate 流程,禁止进入 legacy 入口
280
+ if (device.isProtocolV2()) {
281
+ throw ERRORS.TypedError(
282
+ HardwareErrorCode.RuntimeError,
283
+ 'Protocol V2 firmware update must use firmwareUpdateV4'
284
+ );
285
+ }
286
+
287
+ const deviceFirmwareType = device.getCurrentFirmwareType();
285
288
  const firmwareType = params.firmwareType ?? deviceFirmwareType;
286
289
 
287
290
  this.checkVersionForCopyTouchResource(features, firmwareType);
288
291
 
289
- if (!features?.bootloader_mode && features) {
292
+ if (!device.isBootloader() && features) {
290
293
  const uuid = getDeviceUUID(features);
291
294
  // should go to bootloader mode manually
292
295
  if (this.isEnteredManuallyBoot(features)) {
@@ -18,6 +18,7 @@ import { DataManager } from '../data-manager';
18
18
  import { FirmwareUpdateBaseMethod } from './firmware/FirmwareUpdateBaseMethod';
19
19
  import { DevicePool } from '../device/DevicePool';
20
20
  import { DEVICE } from '../events';
21
+ import { buildProtocolV1FeaturesPayload } from '../deviceProfile';
21
22
 
22
23
  import type { FirmwareUpdateV3Params } from '../types/api/firmwareUpdate';
23
24
  import type { Deferred, EFirmwareType } from '@onekeyfe/hd-shared';
@@ -79,6 +80,20 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
79
80
  }
80
81
 
81
82
  async run() {
83
+ if (this.device.isProtocolV2()) {
84
+ throw ERRORS.TypedError(
85
+ HardwareErrorCode.RuntimeError,
86
+ 'Protocol V2 firmware update must use firmwareUpdateV4'
87
+ );
88
+ }
89
+ Log.debug('FirmwareUpdateV3 strategy: Protocol V1');
90
+ return this.runProtocolV1();
91
+ }
92
+
93
+ /**
94
+ * Protocol V1 firmware update strategy for existing Pro devices.
95
+ */
96
+ private async runProtocolV1() {
82
97
  const { device } = this;
83
98
  const { features } = device;
84
99
 
@@ -251,6 +266,7 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
251
266
  }
252
267
 
253
268
  this.postTipMessage(FirmwareUpdateTipMessage.StartTransferData);
269
+
254
270
  // Process resource zip contents
255
271
  if (resourceBinary) {
256
272
  const file = await JSZip.loadAsync(resourceBinary);
@@ -291,12 +307,10 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
291
307
  }
292
308
  }
293
309
 
294
- // trigger firmware update, support folder updates
310
+ // trigger firmware update
295
311
  try {
296
312
  this.postTipMessage(FirmwareUpdateTipMessage.ConfirmOnDevice);
297
- await this.startEmmcFirmwareUpdate({
298
- path: '0:updates',
299
- });
313
+ await this.startEmmcFirmwareUpdate({ path: '0:updates' });
300
314
  } catch (error) {
301
315
  Log.error('triggerFirmwareUpdateEmmc error: ', error);
302
316
  // Re-throw errors with specific error codes that should not be ignored
@@ -373,7 +387,7 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
373
387
  }),
374
388
  ]);
375
389
  getFeaturesTimeoutCount = 0;
376
- const features = featuresRes.message;
390
+ const features = buildProtocolV1FeaturesPayload(featuresRes.message, this.device.features);
377
391
  const bootloaderVersion = getDeviceBootloaderVersion(features).join('.');
378
392
  const bleVersion = getDeviceBLEFirmwareVersion(features).join('.');
379
393
  const firmwareVersion = getDeviceFirmwareVersion(features).join('.');