@onekeyfe/hd-core 1.1.27-alpha.4 → 1.1.27-alpha.40

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 (362) hide show
  1. package/__tests__/evmSignTransaction.test.ts +1 -1
  2. package/__tests__/evmSignTypedData.test.ts +1 -1
  3. package/__tests__/protocol-v2.test.ts +1661 -0
  4. package/dist/api/BaseMethod.d.ts +1 -7
  5. package/dist/api/BaseMethod.d.ts.map +1 -1
  6. package/dist/api/DirList.d.ts +10 -0
  7. package/dist/api/DirList.d.ts.map +1 -0
  8. package/dist/api/DirMake.d.ts +9 -0
  9. package/dist/api/DirMake.d.ts.map +1 -0
  10. package/dist/api/DirRemove.d.ts +9 -0
  11. package/dist/api/DirRemove.d.ts.map +1 -0
  12. package/dist/api/FileDelete.d.ts +9 -0
  13. package/dist/api/FileDelete.d.ts.map +1 -0
  14. package/dist/api/FileRead.d.ts +19 -0
  15. package/dist/api/FileRead.d.ts.map +1 -0
  16. package/dist/api/FileWrite.d.ts +23 -0
  17. package/dist/api/FileWrite.d.ts.map +1 -0
  18. package/dist/api/FirmwareUpdateV3.d.ts +1 -0
  19. package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
  20. package/dist/api/FirmwareUpdateV4.d.ts +32 -0
  21. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -0
  22. package/dist/api/GetDeviceInfo.d.ts +9 -0
  23. package/dist/api/GetDeviceInfo.d.ts.map +1 -0
  24. package/dist/api/GetFeatures.d.ts +1 -1
  25. package/dist/api/GetOnekeyFeatures.d.ts.map +1 -1
  26. package/dist/api/GetPassphraseState.d.ts +6 -1
  27. package/dist/api/GetPassphraseState.d.ts.map +1 -1
  28. package/dist/api/PathInfo.d.ts +9 -0
  29. package/dist/api/PathInfo.d.ts.map +1 -0
  30. package/dist/api/SearchDevices.d.ts +2 -1
  31. package/dist/api/SearchDevices.d.ts.map +1 -1
  32. package/dist/api/alephium/AlephiumGetAddress.d.ts +2 -6
  33. package/dist/api/alephium/AlephiumGetAddress.d.ts.map +1 -1
  34. package/dist/api/alephium/AlephiumSignMessage.d.ts +2 -5
  35. package/dist/api/alephium/AlephiumSignMessage.d.ts.map +1 -1
  36. package/dist/api/alephium/AlephiumSignTransaction.d.ts +2 -5
  37. package/dist/api/alephium/AlephiumSignTransaction.d.ts.map +1 -1
  38. package/dist/api/algo/AlgoSignTransaction.d.ts.map +1 -1
  39. package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
  40. package/dist/api/aptos/AptosSignInMessage.d.ts.map +1 -1
  41. package/dist/api/aptos/AptosSignMessage.d.ts.map +1 -1
  42. package/dist/api/aptos/AptosSignTransaction.d.ts.map +1 -1
  43. package/dist/api/benfen/BenfenGetAddress.d.ts +2 -9
  44. package/dist/api/benfen/BenfenGetAddress.d.ts.map +1 -1
  45. package/dist/api/benfen/BenfenGetPublicKey.d.ts +2 -9
  46. package/dist/api/benfen/BenfenGetPublicKey.d.ts.map +1 -1
  47. package/dist/api/benfen/BenfenSignMessage.d.ts +2 -8
  48. package/dist/api/benfen/BenfenSignMessage.d.ts.map +1 -1
  49. package/dist/api/benfen/BenfenSignTransaction.d.ts +2 -8
  50. package/dist/api/benfen/BenfenSignTransaction.d.ts.map +1 -1
  51. package/dist/api/btc/BTCGetAddress.d.ts +1 -11
  52. package/dist/api/btc/BTCGetAddress.d.ts.map +1 -1
  53. package/dist/api/btc/BTCGetPublicKey.d.ts +1 -11
  54. package/dist/api/btc/BTCGetPublicKey.d.ts.map +1 -1
  55. package/dist/api/btc/BTCSignMessage.d.ts +1 -15
  56. package/dist/api/btc/BTCSignMessage.d.ts.map +1 -1
  57. package/dist/api/btc/BTCSignPsbt.d.ts.map +1 -1
  58. package/dist/api/btc/BTCSignTransaction.d.ts +1 -11
  59. package/dist/api/btc/BTCSignTransaction.d.ts.map +1 -1
  60. package/dist/api/btc/BTCVerifyMessage.d.ts +1 -11
  61. package/dist/api/btc/BTCVerifyMessage.d.ts.map +1 -1
  62. package/dist/api/btc/helpers/versionLimit.d.ts +2 -11
  63. package/dist/api/btc/helpers/versionLimit.d.ts.map +1 -1
  64. package/dist/api/cardano/CardanoSignMessage.d.ts.map +1 -1
  65. package/dist/api/cardano/CardanoSignTransaction.d.ts.map +1 -1
  66. package/dist/api/conflux/ConfluxSignMessage.d.ts.map +1 -1
  67. package/dist/api/conflux/ConfluxSignMessageCIP23.d.ts.map +1 -1
  68. package/dist/api/conflux/ConfluxSignTransaction.d.ts.map +1 -1
  69. package/dist/api/cosmos/CosmosSignTransaction.d.ts.map +1 -1
  70. package/dist/api/device/DeviceRebootToBoardloader.d.ts +1 -1
  71. package/dist/api/device/DeviceRebootToBoardloader.d.ts.map +1 -1
  72. package/dist/api/device/DeviceRebootToBootloader.d.ts.map +1 -1
  73. package/dist/api/dynex/DnxGetAddress.d.ts.map +1 -1
  74. package/dist/api/dynex/DnxSignTransaction.d.ts.map +1 -1
  75. package/dist/api/evm/EVMSignMessage.d.ts.map +1 -1
  76. package/dist/api/evm/EVMSignMessageEIP712.d.ts +2 -8
  77. package/dist/api/evm/EVMSignMessageEIP712.d.ts.map +1 -1
  78. package/dist/api/evm/EVMSignTransaction.d.ts.map +1 -1
  79. package/dist/api/evm/EVMSignTypedData.d.ts.map +1 -1
  80. package/dist/api/evm/latest/signTypedData.d.ts +1 -1
  81. package/dist/api/evm/latest/signTypedData.d.ts.map +1 -1
  82. package/dist/api/evm/legacyV1/signTypedData.d.ts +1 -1
  83. package/dist/api/evm/legacyV1/signTypedData.d.ts.map +1 -1
  84. package/dist/api/filecoin/FilecoinSignTransaction.d.ts.map +1 -1
  85. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +10 -2
  86. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
  87. package/dist/api/helpers/deviceInfo.d.ts +15 -0
  88. package/dist/api/helpers/deviceInfo.d.ts.map +1 -0
  89. package/dist/api/helpers/filesystemValidation.d.ts +7 -0
  90. package/dist/api/helpers/filesystemValidation.d.ts.map +1 -0
  91. package/dist/api/index.d.ts +28 -1
  92. package/dist/api/index.d.ts.map +1 -1
  93. package/dist/api/kaspa/KaspaSignTransaction.d.ts.map +1 -1
  94. package/dist/api/near/NearSignTransaction.d.ts.map +1 -1
  95. package/dist/api/nem/NEMSignTransaction.d.ts.map +1 -1
  96. package/dist/api/neo/NeoGetAddress.d.ts +2 -8
  97. package/dist/api/neo/NeoGetAddress.d.ts.map +1 -1
  98. package/dist/api/neo/NeoSignTransaction.d.ts +2 -8
  99. package/dist/api/neo/NeoSignTransaction.d.ts.map +1 -1
  100. package/dist/api/nervos/NervosGetAddress.d.ts +2 -9
  101. package/dist/api/nervos/NervosGetAddress.d.ts.map +1 -1
  102. package/dist/api/nervos/NervosSignTransaction.d.ts +2 -9
  103. package/dist/api/nervos/NervosSignTransaction.d.ts.map +1 -1
  104. package/dist/api/nexa/NexaGetAddress.d.ts +2 -8
  105. package/dist/api/nexa/NexaGetAddress.d.ts.map +1 -1
  106. package/dist/api/nexa/NexaSignTransaction.d.ts +2 -9
  107. package/dist/api/nexa/NexaSignTransaction.d.ts.map +1 -1
  108. package/dist/api/nostr/NostrSignEvent.d.ts.map +1 -1
  109. package/dist/api/nostr/NostrSignSchnorr.d.ts.map +1 -1
  110. package/dist/api/polkadot/PolkadotSignTransaction.d.ts.map +1 -1
  111. package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts +7 -0
  112. package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts.map +1 -0
  113. package/dist/api/protocol-v2/DeviceGetDeviceInfo.d.ts +7 -0
  114. package/dist/api/protocol-v2/DeviceGetDeviceInfo.d.ts.map +1 -0
  115. package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts +6 -0
  116. package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts.map +1 -0
  117. package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts +6 -0
  118. package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts.map +1 -0
  119. package/dist/api/protocol-v2/DeviceReboot.d.ts +7 -0
  120. package/dist/api/protocol-v2/DeviceReboot.d.ts.map +1 -0
  121. package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts +7 -0
  122. package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts.map +1 -0
  123. package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts +6 -0
  124. package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts.map +1 -0
  125. package/dist/api/protocol-v2/FilesystemDiskControl.d.ts +10 -0
  126. package/dist/api/protocol-v2/FilesystemDiskControl.d.ts.map +1 -0
  127. package/dist/api/protocol-v2/FilesystemFixPermission.d.ts +6 -0
  128. package/dist/api/protocol-v2/FilesystemFixPermission.d.ts.map +1 -0
  129. package/dist/api/protocol-v2/FilesystemFormat.d.ts +6 -0
  130. package/dist/api/protocol-v2/FilesystemFormat.d.ts.map +1 -0
  131. package/dist/api/protocol-v2/GetProtoVersion.d.ts +6 -0
  132. package/dist/api/protocol-v2/GetProtoVersion.d.ts.map +1 -0
  133. package/dist/api/protocol-v2/Ping.d.ts +8 -0
  134. package/dist/api/protocol-v2/Ping.d.ts.map +1 -0
  135. package/dist/api/protocol-v2/helpers.d.ts +49 -0
  136. package/dist/api/protocol-v2/helpers.d.ts.map +1 -0
  137. package/dist/api/scdo/ScdoGetAddress.d.ts +2 -6
  138. package/dist/api/scdo/ScdoGetAddress.d.ts.map +1 -1
  139. package/dist/api/scdo/ScdoSignMessage.d.ts +2 -5
  140. package/dist/api/scdo/ScdoSignMessage.d.ts.map +1 -1
  141. package/dist/api/scdo/ScdoSignTransaction.d.ts +2 -5
  142. package/dist/api/scdo/ScdoSignTransaction.d.ts.map +1 -1
  143. package/dist/api/solana/SolGetAddress.d.ts +6 -0
  144. package/dist/api/solana/SolGetAddress.d.ts.map +1 -1
  145. package/dist/api/solana/SolSignMessage.d.ts +4 -0
  146. package/dist/api/solana/SolSignMessage.d.ts.map +1 -1
  147. package/dist/api/solana/SolSignOffchainMessage.d.ts +4 -0
  148. package/dist/api/solana/SolSignOffchainMessage.d.ts.map +1 -1
  149. package/dist/api/solana/SolSignTransaction.d.ts +8 -0
  150. package/dist/api/solana/SolSignTransaction.d.ts.map +1 -1
  151. package/dist/api/starcoin/StarcoinSignMessage.d.ts.map +1 -1
  152. package/dist/api/starcoin/StarcoinSignTransaction.d.ts.map +1 -1
  153. package/dist/api/stellar/StellarGetAddress.d.ts +2 -1
  154. package/dist/api/stellar/StellarGetAddress.d.ts.map +1 -1
  155. package/dist/api/stellar/StellarSignTransaction.d.ts +2 -1
  156. package/dist/api/stellar/StellarSignTransaction.d.ts.map +1 -1
  157. package/dist/api/sui/SuiSignMessage.d.ts.map +1 -1
  158. package/dist/api/sui/SuiSignTransaction.d.ts +2 -2
  159. package/dist/api/sui/SuiSignTransaction.d.ts.map +1 -1
  160. package/dist/api/ton/TonSignData.d.ts.map +1 -1
  161. package/dist/api/ton/TonSignMessage.d.ts.map +1 -1
  162. package/dist/api/ton/TonSignProof.d.ts.map +1 -1
  163. package/dist/api/tron/TronGetAddress.d.ts +4 -0
  164. package/dist/api/tron/TronGetAddress.d.ts.map +1 -1
  165. package/dist/api/tron/TronSignMessage.d.ts +4 -0
  166. package/dist/api/tron/TronSignMessage.d.ts.map +1 -1
  167. package/dist/api/tron/TronSignTransaction.d.ts +4 -0
  168. package/dist/api/tron/TronSignTransaction.d.ts.map +1 -1
  169. package/dist/api/xrp/XrpSignTransaction.d.ts.map +1 -1
  170. package/dist/core/RequestQueue.d.ts +1 -1
  171. package/dist/core/RequestQueue.d.ts.map +1 -1
  172. package/dist/core/index.d.ts.map +1 -1
  173. package/dist/data-manager/DataManager.d.ts +7 -4
  174. package/dist/data-manager/DataManager.d.ts.map +1 -1
  175. package/dist/data-manager/MessagesConfig.d.ts +2 -2
  176. package/dist/data-manager/MessagesConfig.d.ts.map +1 -1
  177. package/dist/data-manager/TransportManager.d.ts +5 -4
  178. package/dist/data-manager/TransportManager.d.ts.map +1 -1
  179. package/dist/device/Device.d.ts +5 -18
  180. package/dist/device/Device.d.ts.map +1 -1
  181. package/dist/device/DeviceCommands.d.ts +8 -8
  182. package/dist/device/DeviceCommands.d.ts.map +1 -1
  183. package/dist/device/DeviceConnector.d.ts +2 -1
  184. package/dist/device/DeviceConnector.d.ts.map +1 -1
  185. package/dist/events/ui-request.d.ts +8 -0
  186. package/dist/events/ui-request.d.ts.map +1 -1
  187. package/dist/index.d.ts +292 -43
  188. package/dist/index.js +16693 -1497
  189. package/dist/inject.d.ts.map +1 -1
  190. package/dist/protocols/protocol-v2/features.d.ts +104 -0
  191. package/dist/protocols/protocol-v2/features.d.ts.map +1 -0
  192. package/dist/protocols/protocol-v2/firmware.d.ts +12 -0
  193. package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -0
  194. package/dist/protocols/protocol-v2/index.d.ts +3 -0
  195. package/dist/protocols/protocol-v2/index.d.ts.map +1 -0
  196. package/dist/types/api/export.d.ts +1 -1
  197. package/dist/types/api/export.d.ts.map +1 -1
  198. package/dist/types/api/firmwareUpdate.d.ts +7 -0
  199. package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
  200. package/dist/types/api/getDeviceInfo.d.ts +84 -0
  201. package/dist/types/api/getDeviceInfo.d.ts.map +1 -0
  202. package/dist/types/api/getPassphraseState.d.ts +10 -1
  203. package/dist/types/api/getPassphraseState.d.ts.map +1 -1
  204. package/dist/types/api/index.d.ts +33 -3
  205. package/dist/types/api/index.d.ts.map +1 -1
  206. package/dist/types/api/protocolV2.d.ts +127 -0
  207. package/dist/types/api/protocolV2.d.ts.map +1 -0
  208. package/dist/types/api/searchDevices.d.ts +2 -2
  209. package/dist/types/api/searchDevices.d.ts.map +1 -1
  210. package/dist/types/device.d.ts +6 -2
  211. package/dist/types/device.d.ts.map +1 -1
  212. package/dist/types/params.d.ts +2 -1
  213. package/dist/types/params.d.ts.map +1 -1
  214. package/dist/types/settings.d.ts +1 -1
  215. package/dist/types/settings.d.ts.map +1 -1
  216. package/dist/utils/deviceFeaturesUtils.d.ts +5 -3
  217. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  218. package/dist/utils/deviceInfoUtils.d.ts +1 -0
  219. package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
  220. package/dist/utils/index.d.ts +1 -1
  221. package/dist/utils/index.d.ts.map +1 -1
  222. package/dist/utils/patch.d.ts +1 -1
  223. package/dist/utils/patch.d.ts.map +1 -1
  224. package/dist/utils/versionUtils.d.ts +1 -1
  225. package/package.json +4 -4
  226. package/src/api/BaseMethod.ts +7 -82
  227. package/src/api/DirList.ts +29 -0
  228. package/src/api/DirMake.ts +21 -0
  229. package/src/api/DirRemove.ts +21 -0
  230. package/src/api/FileDelete.ts +21 -0
  231. package/src/api/FileRead.ts +165 -0
  232. package/src/api/FileWrite.ts +203 -0
  233. package/src/api/FirmwareUpdateV3.ts +21 -4
  234. package/src/api/FirmwareUpdateV4.ts +810 -0
  235. package/src/api/GetDeviceInfo.ts +161 -0
  236. package/src/api/GetOnekeyFeatures.ts +75 -3
  237. package/src/api/GetPassphraseState.ts +16 -7
  238. package/src/api/PathInfo.ts +25 -0
  239. package/src/api/SearchDevices.ts +7 -2
  240. package/src/api/alephium/AlephiumGetAddress.ts +6 -2
  241. package/src/api/alephium/AlephiumSignMessage.ts +6 -2
  242. package/src/api/alephium/AlephiumSignTransaction.ts +6 -3
  243. package/src/api/algo/AlgoSignTransaction.ts +0 -1
  244. package/src/api/allnetwork/AllNetworkGetAddressBase.ts +18 -9
  245. package/src/api/aptos/AptosSignInMessage.ts +0 -1
  246. package/src/api/aptos/AptosSignMessage.ts +0 -1
  247. package/src/api/aptos/AptosSignTransaction.ts +0 -1
  248. package/src/api/benfen/BenfenGetAddress.ts +6 -2
  249. package/src/api/benfen/BenfenGetPublicKey.ts +6 -2
  250. package/src/api/benfen/BenfenSignMessage.ts +6 -2
  251. package/src/api/benfen/BenfenSignTransaction.ts +6 -2
  252. package/src/api/btc/BTCSignMessage.ts +0 -1
  253. package/src/api/btc/BTCSignPsbt.ts +0 -1
  254. package/src/api/btc/BTCSignTransaction.ts +0 -1
  255. package/src/api/btc/helpers/versionLimit.ts +7 -1
  256. package/src/api/cardano/CardanoSignMessage.ts +0 -1
  257. package/src/api/cardano/CardanoSignTransaction.ts +0 -1
  258. package/src/api/conflux/ConfluxSignMessage.ts +0 -1
  259. package/src/api/conflux/ConfluxSignMessageCIP23.ts +0 -1
  260. package/src/api/conflux/ConfluxSignTransaction.ts +5 -3
  261. package/src/api/cosmos/CosmosSignTransaction.ts +0 -1
  262. package/src/api/device/DeviceRebootToBoardloader.ts +10 -1
  263. package/src/api/device/DeviceRebootToBootloader.ts +10 -1
  264. package/src/api/dynex/DnxGetAddress.ts +7 -0
  265. package/src/api/dynex/DnxSignTransaction.ts +7 -1
  266. package/src/api/evm/EVMGetAddress.ts +1 -1
  267. package/src/api/evm/EVMGetPublicKey.ts +1 -1
  268. package/src/api/evm/EVMSignMessage.ts +1 -3
  269. package/src/api/evm/EVMSignMessageEIP712.ts +14 -2
  270. package/src/api/evm/EVMSignTransaction.ts +1 -3
  271. package/src/api/evm/EVMSignTypedData.ts +6 -8
  272. package/src/api/evm/EVMVerifyMessage.ts +1 -1
  273. package/src/api/filecoin/FilecoinSignTransaction.ts +0 -1
  274. package/src/api/firmware/FirmwareUpdateBaseMethod.ts +27 -4
  275. package/src/api/helpers/deviceInfo.ts +205 -0
  276. package/src/api/helpers/filesystemValidation.ts +51 -0
  277. package/src/api/index.ts +30 -1
  278. package/src/api/kaspa/KaspaSignTransaction.ts +0 -1
  279. package/src/api/near/NearSignTransaction.ts +0 -1
  280. package/src/api/nem/NEMSignTransaction.ts +0 -1
  281. package/src/api/neo/NeoGetAddress.ts +6 -1
  282. package/src/api/neo/NeoSignTransaction.ts +6 -2
  283. package/src/api/nervos/NervosGetAddress.ts +6 -2
  284. package/src/api/nervos/NervosSignTransaction.ts +6 -3
  285. package/src/api/nexa/NexaGetAddress.ts +6 -2
  286. package/src/api/nexa/NexaSignTransaction.ts +6 -4
  287. package/src/api/nostr/NostrSignEvent.ts +0 -1
  288. package/src/api/nostr/NostrSignSchnorr.ts +0 -1
  289. package/src/api/polkadot/PolkadotSignTransaction.ts +0 -1
  290. package/src/api/protocol-v2/DeviceFirmwareUpdate.ts +50 -0
  291. package/src/api/protocol-v2/DeviceGetDeviceInfo.ts +35 -0
  292. package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +18 -0
  293. package/src/api/protocol-v2/DeviceGetOnboardingStatus.ts +18 -0
  294. package/src/api/protocol-v2/DeviceReboot.ts +22 -0
  295. package/src/api/protocol-v2/FactoryDeviceInfoSettings.ts +27 -0
  296. package/src/api/protocol-v2/FactoryGetDeviceInfo.ts +18 -0
  297. package/src/api/protocol-v2/FilesystemDiskControl.ts +34 -0
  298. package/src/api/protocol-v2/FilesystemFixPermission.ts +14 -0
  299. package/src/api/protocol-v2/FilesystemFormat.ts +14 -0
  300. package/src/api/protocol-v2/GetProtoVersion.ts +14 -0
  301. package/src/api/protocol-v2/Ping.ts +16 -0
  302. package/src/api/protocol-v2/helpers.ts +161 -0
  303. package/src/api/scdo/ScdoGetAddress.ts +6 -2
  304. package/src/api/scdo/ScdoSignMessage.ts +6 -2
  305. package/src/api/scdo/ScdoSignTransaction.ts +6 -3
  306. package/src/api/solana/SolGetAddress.ts +9 -0
  307. package/src/api/solana/SolSignMessage.ts +4 -1
  308. package/src/api/solana/SolSignOffchainMessage.ts +4 -1
  309. package/src/api/solana/SolSignTransaction.ts +8 -1
  310. package/src/api/starcoin/StarcoinSignMessage.ts +0 -1
  311. package/src/api/starcoin/StarcoinSignTransaction.ts +0 -1
  312. package/src/api/stellar/StellarGetAddress.ts +10 -1
  313. package/src/api/stellar/StellarSignTransaction.ts +14 -2
  314. package/src/api/sui/SuiSignMessage.ts +0 -1
  315. package/src/api/sui/SuiSignTransaction.ts +12 -10
  316. package/src/api/ton/TonSignData.ts +0 -1
  317. package/src/api/ton/TonSignMessage.ts +0 -1
  318. package/src/api/ton/TonSignProof.ts +0 -1
  319. package/src/api/tron/TronGetAddress.ts +4 -0
  320. package/src/api/tron/TronSignMessage.ts +5 -2
  321. package/src/api/tron/TronSignTransaction.ts +4 -1
  322. package/src/api/xrp/XrpSignTransaction.ts +1 -2
  323. package/src/core/RequestQueue.ts +3 -10
  324. package/src/core/index.ts +62 -153
  325. package/src/data/messages/messages-protocol-v2.json +13128 -0
  326. package/src/data-manager/DataManager.ts +12 -7
  327. package/src/data-manager/MessagesConfig.ts +14 -14
  328. package/src/data-manager/TransportManager.ts +38 -12
  329. package/src/device/Device.ts +88 -77
  330. package/src/device/DeviceCommands.ts +166 -26
  331. package/src/device/DeviceConnector.ts +29 -4
  332. package/src/device/DevicePool.ts +1 -1
  333. package/src/events/ui-request.ts +8 -0
  334. package/src/inject.ts +46 -2
  335. package/src/protocols/protocol-v2/features.ts +287 -0
  336. package/src/protocols/protocol-v2/firmware.ts +26 -0
  337. package/src/protocols/protocol-v2/index.ts +2 -0
  338. package/src/types/api/export.ts +1 -0
  339. package/src/types/api/firmwareUpdate.ts +12 -0
  340. package/src/types/api/getDeviceInfo.ts +97 -0
  341. package/src/types/api/getPassphraseState.ts +13 -2
  342. package/src/types/api/index.ts +80 -3
  343. package/src/types/api/protocolV2.ts +226 -0
  344. package/src/types/api/searchDevices.ts +2 -2
  345. package/src/types/device.ts +33 -2
  346. package/src/types/params.ts +4 -2
  347. package/src/types/settings.ts +1 -1
  348. package/src/utils/deviceFeaturesUtils.ts +62 -21
  349. package/src/utils/deviceInfoUtils.ts +15 -8
  350. package/src/utils/index.ts +1 -0
  351. package/__tests__/DeviceCommands.test.ts +0 -99
  352. package/__tests__/evmLedgerLegacySafety.test.ts +0 -261
  353. package/__tests__/preInitialize.test.ts +0 -22
  354. package/dist/api/device/PreInitialize.d.ts +0 -6
  355. package/dist/api/device/PreInitialize.d.ts.map +0 -1
  356. package/dist/core/PollingStateManager.d.ts +0 -8
  357. package/dist/core/PollingStateManager.d.ts.map +0 -1
  358. package/dist/types/api/preInitialize.d.ts +0 -3
  359. package/dist/types/api/preInitialize.d.ts.map +0 -1
  360. package/src/api/device/PreInitialize.ts +0 -41
  361. package/src/core/PollingStateManager.ts +0 -47
  362. package/src/types/api/preInitialize.ts +0 -3
@@ -14,7 +14,6 @@ export default class CardanoSignMessage extends BaseMethod<CardanoSignMessagePar
14
14
  init() {
15
15
  this.checkDeviceId = true;
16
16
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
17
- this.allowUsePreInitialize = true;
18
17
 
19
18
  const { payload } = this;
20
19
  validateParams(payload, [
@@ -49,7 +49,6 @@ export default class CardanoSignTransaction extends BaseMethod<any> {
49
49
  init() {
50
50
  this.checkDeviceId = true;
51
51
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
52
- this.allowUsePreInitialize = true;
53
52
 
54
53
  this.hasBundle = !!this.payload?.bundle;
55
54
 
@@ -9,7 +9,6 @@ import type { ConfluxSignMessage as HardwareConfluxSignMessage } from '@onekeyfe
9
9
  export default class ConfluxSignMessage extends BaseMethod<HardwareConfluxSignMessage> {
10
10
  init() {
11
11
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
12
- this.allowUsePreInitialize = true;
13
12
 
14
13
  // check payload
15
14
  validateParams(this.payload, [
@@ -9,7 +9,6 @@ import type { ConfluxSignMessageCIP23 as HardwareConfluxSignMessageCIP23 } from
9
9
  export default class ConfluxSignMessageCIP23 extends BaseMethod<HardwareConfluxSignMessageCIP23> {
10
10
  init() {
11
11
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
12
- this.allowUsePreInitialize = true;
13
12
 
14
13
  validateParams(this.payload, [
15
14
  { name: 'path', required: true },
@@ -22,7 +22,6 @@ export default class ConfluxSignTransaction extends BaseMethod {
22
22
 
23
23
  init() {
24
24
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
25
- this.allowUsePreInitialize = true;
26
25
 
27
26
  validateParams(this.payload, [
28
27
  { name: 'path', required: true },
@@ -35,7 +34,7 @@ export default class ConfluxSignTransaction extends BaseMethod {
35
34
 
36
35
  // check if transaction is valid
37
36
  const schema: SchemaParam[] = [
38
- { name: 'to', type: 'hexString', required: true },
37
+ { name: 'to', type: 'string', required: true },
39
38
  { name: 'value', type: 'hexString', required: true },
40
39
  { name: 'gasLimit', type: 'hexString', required: true },
41
40
  { name: 'gasPrice', type: 'hexString', required: true },
@@ -48,7 +47,10 @@ export default class ConfluxSignTransaction extends BaseMethod {
48
47
 
49
48
  validateParams(tx, schema);
50
49
 
51
- this.formattedTx = formatAnyHex(tx);
50
+ this.formattedTx = {
51
+ ...formatAnyHex(tx),
52
+ to: tx.to,
53
+ };
52
54
  }
53
55
 
54
56
  processTxRequest = async (request: ConfluxTxRequest, data: string): Promise<ConfluxSignedTx> => {
@@ -14,7 +14,6 @@ export default class CosmosSignTransaction extends BaseMethod<HardwareCosmosSign
14
14
  init() {
15
15
  this.checkDeviceId = true;
16
16
  this.allowDeviceMode = [...this.allowDeviceMode];
17
- this.allowUsePreInitialize = true;
18
17
 
19
18
  // check payload
20
19
  validateParams(this.payload, [
@@ -1,3 +1,5 @@
1
+ import { DeviceRebootType } from '@onekeyfe/hd-transport';
2
+
1
3
  import { BaseMethod } from '../BaseMethod';
2
4
 
3
5
  import type { RebootToBoardloaderParams } from '../../types/api/deviceRebootToBoardloader';
@@ -21,10 +23,17 @@ export default class DeviceRebootToBoardloader extends BaseMethod<RebootToBoardl
21
23
  }
22
24
 
23
25
  async run() {
26
+ // Protocol V2 uses DeviceReboot with reboot_type enum.
27
+ if (this.device.originalDescriptor?.protocolType === 'V2') {
28
+ const res = await this.device.commands.typedCall('DeviceReboot', 'Success', {
29
+ reboot_type: DeviceRebootType.Boardloader,
30
+ });
31
+ return Promise.resolve(res.message);
32
+ }
33
+
24
34
  // On Touch devices, messsage code 904 is RebootToBoardloader
25
35
  // so BininOutMessageSE message code 904 is used here
26
36
  const res = await this.device.commands.typedCall('BixinOutMessageSE', 'Success');
27
-
28
37
  return Promise.resolve(res.message);
29
38
  }
30
39
  }
@@ -1,3 +1,5 @@
1
+ import { DeviceRebootType } from '@onekeyfe/hd-transport';
2
+
1
3
  import { BaseMethod } from '../BaseMethod';
2
4
 
3
5
  import type { RebootToBootloader } from '@onekeyfe/hd-transport';
@@ -21,8 +23,15 @@ export default class DeviceRebootToBootloader extends BaseMethod<RebootToBootloa
21
23
  }
22
24
 
23
25
  async run() {
24
- const res = await this.device.commands.typedCall('RebootToBootloader', 'Success');
26
+ // Protocol V2 uses DeviceReboot with reboot_type enum.
27
+ if (this.device.originalDescriptor?.protocolType === 'V2') {
28
+ const res = await this.device.commands.typedCall('DeviceReboot', 'Success', {
29
+ reboot_type: DeviceRebootType.Bootloader,
30
+ });
31
+ return Promise.resolve(res.message);
32
+ }
25
33
 
34
+ const res = await this.device.commands.typedCall('RebootToBootloader', 'Success');
26
35
  return Promise.resolve(res.message);
27
36
  }
28
37
  }
@@ -1,7 +1,10 @@
1
+ import { createDeviceNotSupportMethodError } from '@onekeyfe/hd-shared';
2
+
1
3
  import { UI_REQUEST } from '../../constants/ui-request';
2
4
  import { serializedPath, validatePath } from '../helpers/pathUtils';
3
5
  import { BaseMethod } from '../BaseMethod';
4
6
  import { validateParams, validateResult } from '../helpers/paramsValidator';
7
+ import { getFirmwareType } from '../../utils';
5
8
 
6
9
  import type { DnxGetAddress as HardwareDnxGetAddress } from '@onekeyfe/hd-transport';
7
10
  import type { DnxAddress, DnxGetAddressParams } from '../../types';
@@ -47,6 +50,10 @@ export default class DnxGetAddress extends BaseMethod<HardwareDnxGetAddress[]> {
47
50
  }
48
51
 
49
52
  async run() {
53
+ if (this.device.originalDescriptor?.protocolType === 'V2') {
54
+ throw createDeviceNotSupportMethodError(this.name, getFirmwareType(this.device.features));
55
+ }
56
+
50
57
  const responses: DnxAddress[] = [];
51
58
 
52
59
  for (let i = 0; i < this.params.length; i++) {
@@ -1,8 +1,11 @@
1
+ import { createDeviceNotSupportMethodError } from '@onekeyfe/hd-shared';
2
+
1
3
  import { UI_REQUEST } from '../../constants/ui-request';
2
4
  import { serializedPath, validatePath } from '../helpers/pathUtils';
3
5
  import { BaseMethod } from '../BaseMethod';
4
6
  import { validateParams } from '../helpers/paramsValidator';
5
7
  import { stripHexPrefix } from '../helpers/hexUtils';
8
+ import { getFirmwareType } from '../../utils';
6
9
 
7
10
  import type { TypedResponseMessage } from '../../device/DeviceCommands';
8
11
  import type { DnxSignature } from '../../types';
@@ -14,7 +17,6 @@ export default class DnxSignTransaction extends BaseMethod<DnxSignTx> {
14
17
  init() {
15
18
  this.checkDeviceId = true;
16
19
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
17
- this.allowUsePreInitialize = true;
18
20
 
19
21
  const { payload } = this;
20
22
  // init params
@@ -116,6 +118,10 @@ export default class DnxSignTransaction extends BaseMethod<DnxSignTx> {
116
118
  }
117
119
 
118
120
  async run() {
121
+ if (this.device.originalDescriptor?.protocolType === 'V2') {
122
+ throw createDeviceNotSupportMethodError(this.name, getFirmwareType(this.device.features));
123
+ }
124
+
119
125
  const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
120
126
 
121
127
  const res = await this.device.commands.typedCall('DnxSignTx', 'DnxInputRequest', {
@@ -44,7 +44,7 @@ export default class EvmGetAddress extends BaseMethod<EthereumGetAddressOneKey[]
44
44
  }
45
45
 
46
46
  async getEvmAddress(param: EthereumGetAddressOneKey) {
47
- if (TransportManager.getMessageVersion() === 'v1') {
47
+ if (TransportManager.getProtocolV1MessageSchema() === 'v1LegacySchema') {
48
48
  return getAddressLegacyV1({
49
49
  typedCall: this.device.commands.typedCall.bind(this.device.commands),
50
50
  param,
@@ -57,7 +57,7 @@ export default class EVMGetPublicKey extends BaseMethod<EthereumGetPublicKeyOneK
57
57
  }
58
58
 
59
59
  getEvmPublicKey(param: EthereumGetPublicKey) {
60
- if (TransportManager.getMessageVersion() === 'v1') {
60
+ if (TransportManager.getProtocolV1MessageSchema() === 'v1LegacySchema') {
61
61
  return getPublicKeyLegacyV1({
62
62
  typedCall: this.device.commands.typedCall.bind(this.device.commands),
63
63
  param,
@@ -13,14 +13,12 @@ export default class EVMSignMessage extends BaseMethod<EthereumSignMessageOneKey
13
13
  init() {
14
14
  this.checkDeviceId = true;
15
15
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
16
- this.allowUsePreInitialize = true;
17
16
 
18
17
  // check payload
19
18
  validateParams(this.payload, [
20
19
  { name: 'path', required: true },
21
20
  { name: 'messageHex', type: 'hexString', required: true },
22
21
  { name: 'chainId', type: 'number' },
23
- { name: 'usePreInitialize', type: 'boolean' },
24
22
  ]);
25
23
 
26
24
  const { path, messageHex, chainId } = this.payload;
@@ -36,7 +34,7 @@ export default class EVMSignMessage extends BaseMethod<EthereumSignMessageOneKey
36
34
  }
37
35
 
38
36
  async run() {
39
- if (TransportManager.getMessageVersion() === 'v1') {
37
+ if (TransportManager.getProtocolV1MessageSchema() === 'v1LegacySchema') {
40
38
  return signMessageLegacyV1({
41
39
  typedCall: this.device.commands.typedCall.bind(this.device.commands),
42
40
  params: this.params,
@@ -5,6 +5,7 @@ import { validateParams } from '../helpers/paramsValidator';
5
5
  import { formatAnyHex } from '../helpers/hexUtils';
6
6
 
7
7
  import type { EthereumSignMessageEIP712 } from '@onekeyfe/hd-transport';
8
+ import type { DeviceFirmwareRange } from '../../types';
8
9
 
9
10
  /**
10
11
  * @deprecated Use EVMSignTypedData instead.
@@ -13,7 +14,6 @@ export default class EVMSignMessageEIP712 extends BaseMethod<EthereumSignMessage
13
14
  init() {
14
15
  this.checkDeviceId = true;
15
16
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
16
- this.allowUsePreInitialize = true;
17
17
 
18
18
  validateParams(this.payload, [
19
19
  { name: 'path', required: true },
@@ -32,8 +32,12 @@ export default class EVMSignMessageEIP712 extends BaseMethod<EthereumSignMessage
32
32
  };
33
33
  }
34
34
 
35
- getVersionRange() {
35
+ getVersionRange(): DeviceFirmwareRange {
36
36
  return {
37
+ pro2: {
38
+ min: '0.0.0',
39
+ unsupported: true,
40
+ },
37
41
  model_mini: {
38
42
  min: '2.1.9',
39
43
  },
@@ -44,6 +48,14 @@ export default class EVMSignMessageEIP712 extends BaseMethod<EthereumSignMessage
44
48
  }
45
49
 
46
50
  async run() {
51
+ this.checkFeatureVersionLimit(
52
+ () => true,
53
+ () => this.getVersionRange(),
54
+ {
55
+ strictCheckDeviceSupport: true,
56
+ }
57
+ );
58
+
47
59
  const res = await this.device.commands.typedCall(
48
60
  'EthereumSignMessageEIP712',
49
61
  'EthereumMessageSignature',
@@ -46,12 +46,10 @@ export default class EVMSignTransaction extends BaseMethod {
46
46
  init() {
47
47
  this.checkDeviceId = true;
48
48
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
49
- this.allowUsePreInitialize = true;
50
49
 
51
50
  validateParams(this.payload, [
52
51
  { name: 'path', required: true },
53
52
  { name: 'transaction', type: 'object', required: true },
54
- { name: 'usePreInitialize', type: 'boolean' },
55
53
  ]);
56
54
  const { path, transaction } = this.payload;
57
55
  this.addressN = validatePath(path, 3);
@@ -122,7 +120,7 @@ export default class EVMSignTransaction extends BaseMethod {
122
120
 
123
121
  if (formattedTx == null) throw ERRORS.TypedError('Runtime', 'formattedTx is not set');
124
122
 
125
- if (TransportManager.getMessageVersion() === 'v1') {
123
+ if (TransportManager.getProtocolV1MessageSchema() === 'v1LegacySchema') {
126
124
  return signTransactionLegacyV1({
127
125
  typedCall: this.device.commands.typedCall.bind(this.device.commands),
128
126
  addressN,
@@ -52,7 +52,6 @@ export default class EVMSignTypedData extends BaseMethod<EVMSignTypedDataParams>
52
52
  init() {
53
53
  this.checkDeviceId = true;
54
54
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
55
- this.allowUsePreInitialize = true;
56
55
 
57
56
  validateParams(this.payload, [
58
57
  { name: 'path', required: true },
@@ -61,7 +60,6 @@ export default class EVMSignTypedData extends BaseMethod<EVMSignTypedDataParams>
61
60
  { name: 'domainHash', type: 'hexString' },
62
61
  { name: 'messageHash', type: 'hexString' },
63
62
  { name: 'chainId', type: 'number' },
64
- { name: 'usePreInitialize', type: 'boolean' },
65
63
  ]);
66
64
 
67
65
  const { path, data, metamaskV4Compat, domainHash, messageHash, chainId } = this.payload;
@@ -262,8 +260,8 @@ export default class EVMSignTypedData extends BaseMethod<EVMSignTypedDataParams>
262
260
 
263
261
  let supportTrezor = false;
264
262
  let response: MessageResponse<MessageKey>;
265
- switch (TransportManager.getMessageVersion()) {
266
- case 'v1':
263
+ switch (TransportManager.getProtocolV1MessageSchema()) {
264
+ case 'v1LegacySchema':
267
265
  supportTrezor = true;
268
266
  response = await signTypedDataLegacyV1({
269
267
  typedCall: this.device.commands.typedCall.bind(this.device.commands),
@@ -274,7 +272,7 @@ export default class EVMSignTypedData extends BaseMethod<EVMSignTypedDataParams>
274
272
  });
275
273
  break;
276
274
 
277
- case 'latest':
275
+ case 'v1CurrentSchema':
278
276
  default:
279
277
  supportTrezor = false;
280
278
  response = await signTypedData({
@@ -310,8 +308,8 @@ export default class EVMSignTypedData extends BaseMethod<EVMSignTypedDataParams>
310
308
  }) {
311
309
  if (!domainHash) throw ERRORS.TypedError('Runtime', 'domainHash is required');
312
310
 
313
- switch (TransportManager.getMessageVersion()) {
314
- case 'v1':
311
+ switch (TransportManager.getProtocolV1MessageSchema()) {
312
+ case 'v1LegacySchema':
315
313
  return signTypedHashLegacyV1({
316
314
  typedCall,
317
315
  addressN,
@@ -321,7 +319,7 @@ export default class EVMSignTypedData extends BaseMethod<EVMSignTypedDataParams>
321
319
  device: this.device,
322
320
  });
323
321
 
324
- case 'latest':
322
+ case 'v1CurrentSchema':
325
323
  default:
326
324
  return signTypedHash({
327
325
  typedCall,
@@ -31,7 +31,7 @@ export default class EVMSignMessage extends BaseMethod<EthereumVerifyMessageOneK
31
31
  }
32
32
 
33
33
  async run() {
34
- if (TransportManager.getMessageVersion() === 'v1') {
34
+ if (TransportManager.getProtocolV1MessageSchema() === 'v1LegacySchema') {
35
35
  return verifyMessageLegacyV1({
36
36
  typedCall: this.device.commands.typedCall.bind(this.device.commands),
37
37
  params: this.params,
@@ -12,7 +12,6 @@ export default class FilecoinSignTransaction extends BaseMethod<HardwareFilecoin
12
12
  init() {
13
13
  this.checkDeviceId = true;
14
14
  this.allowDeviceMode = [...this.allowDeviceMode];
15
- this.allowUsePreInitialize = true;
16
15
 
17
16
  // check payload
18
17
  validateParams(this.payload, [
@@ -28,6 +28,13 @@ const Log = getLogger(LoggerNames.Method);
28
28
  const SESSION_ERROR = 'session not found';
29
29
  const FIRMWARE_UPDATE_CONFIRM = 'Firmware install confirmed';
30
30
 
31
+ type FirmwareProgressMetadata = {
32
+ transferredBytes?: number;
33
+ totalBytes?: number;
34
+ rateBytesPerSecond?: number;
35
+ elapsedMs?: number;
36
+ };
37
+
31
38
  const isDeviceDisconnectedError = (error: unknown) => {
32
39
  const message = error instanceof Error ? error.message : String(error ?? '');
33
40
  return (
@@ -82,12 +89,17 @@ export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
82
89
  * @description Post the progress message
83
90
  * @param progress Post the percentage of the progress
84
91
  */
85
- postProgressMessage = (progress: number, progressType: IFirmwareUpdateProgressType) => {
92
+ postProgressMessage = (
93
+ progress: number,
94
+ progressType: IFirmwareUpdateProgressType,
95
+ metadata: FirmwareProgressMetadata = {}
96
+ ) => {
86
97
  this.postMessage(
87
98
  createUiMessage(UI_REQUEST.FIRMWARE_PROGRESS, {
88
99
  device: this.device.toMessageObject() as KnownDevice,
89
100
  progress,
90
101
  progressType,
102
+ ...metadata,
91
103
  })
92
104
  );
93
105
  };
@@ -325,10 +337,12 @@ export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
325
337
  filePath,
326
338
  processedSize,
327
339
  totalSize,
340
+ transferStartTime = Date.now(),
328
341
  }: PROTO.FirmwareUpload & {
329
342
  filePath: string;
330
343
  processedSize?: number;
331
344
  totalSize?: number;
345
+ transferStartTime?: number;
332
346
  }) {
333
347
  if (!filePath.startsWith('0:')) {
334
348
  throw new Error('filePath must start with 0:');
@@ -338,7 +352,6 @@ export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
338
352
  const chunkSize = 1024 * perPackageSize;
339
353
  const totalChunks = Math.ceil(payload.byteLength / chunkSize);
340
354
  let offset = 0;
341
- let currentFileProcessed = 0;
342
355
 
343
356
  for (let i = 0; i < totalChunks; i++) {
344
357
  const chunkStart = i * chunkSize;
@@ -350,7 +363,7 @@ export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
350
363
  // Calculate progress based on whether we're tracking overall progress or single file progress
351
364
  let progress: number;
352
365
  if (totalSize !== undefined && processedSize !== undefined) {
353
- currentFileProcessed = processedSize + chunkEnd;
366
+ const currentFileProcessed = processedSize + chunkEnd;
354
367
  progress = Math.min(Math.ceil((currentFileProcessed / totalSize) * 100), 99);
355
368
  } else {
356
369
  progress = Math.min(Math.ceil(((i + 1) / totalChunks) * 100), 99);
@@ -366,7 +379,17 @@ export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
366
379
  );
367
380
  // @ts-expect-error
368
381
  offset += writeRes.message.processed_byte;
369
- this.postProgressMessage(progress, 'transferData');
382
+ const elapsedMs = Date.now() - transferStartTime;
383
+ const transferredBytes =
384
+ totalSize !== undefined && processedSize !== undefined ? processedSize + offset : offset;
385
+ const totalBytes = totalSize ?? payload.byteLength;
386
+ this.postProgressMessage(progress, 'transferData', {
387
+ transferredBytes,
388
+ totalBytes,
389
+ rateBytesPerSecond:
390
+ elapsedMs > 0 ? Math.round((transferredBytes / elapsedMs) * 1000) : undefined,
391
+ elapsedMs,
392
+ });
370
393
  }
371
394
 
372
395
  // Return processed size only if we're tracking overall progress
@@ -0,0 +1,205 @@
1
+ import {
2
+ getDeviceBLEFirmwareVersion,
3
+ getDeviceBleName,
4
+ getDeviceBoardloaderVersion,
5
+ getDeviceBootloaderVersion,
6
+ getDeviceFirmwareVersion,
7
+ getDeviceLabel,
8
+ getDeviceType,
9
+ getDeviceUUID,
10
+ getFirmwareType,
11
+ } from '../../utils';
12
+
13
+ import type {
14
+ DeviceInfoProtocol,
15
+ DeviceInfoSource,
16
+ DeviceInfoStatus,
17
+ GetDeviceInfoParams,
18
+ UnifiedDeviceInfo,
19
+ UnifiedDeviceInfoRaw,
20
+ UnifiedDeviceInfoVerify,
21
+ UnifiedDeviceInfoVersions,
22
+ } from '../../types/api/getDeviceInfo';
23
+ import type { Features, OnekeyFeatures } from '../../types';
24
+ import type { ProtocolV2DeviceInfo } from '@onekeyfe/hd-transport';
25
+
26
+ type BuildDeviceInfoParams = {
27
+ protocol: DeviceInfoProtocol;
28
+ features?: Features;
29
+ onekeyFeatures?: OnekeyFeatures;
30
+ protocolV2DeviceInfo?: ProtocolV2DeviceInfo;
31
+ sources: DeviceInfoSource[];
32
+ scope?: GetDeviceInfoParams['scope'];
33
+ includeRaw?: boolean;
34
+ };
35
+
36
+ const isMeaningfulVersion = (version?: string | null) => Boolean(version && version !== '0.0.0');
37
+
38
+ const versionArrayToString = (version?: Array<number | string | null> | null) => {
39
+ if (!version || version.length === 0) return null;
40
+ const value = version.join('.');
41
+ return isMeaningfulVersion(value) ? value : null;
42
+ };
43
+
44
+ const firstVersion = (...versions: Array<string | null | undefined>) =>
45
+ versions.find(isMeaningfulVersion) ?? null;
46
+
47
+ const safeGetDeviceUUID = (features?: Features) => (features ? getDeviceUUID(features) : '');
48
+
49
+ const shouldIncludeVerify = (scope?: GetDeviceInfoParams['scope']) =>
50
+ scope === 'verify' || scope === 'full';
51
+
52
+ const getDeviceMode = (features?: Features): DeviceInfoStatus['mode'] => {
53
+ if (!features) return 'unknown';
54
+ if (features.bootloader_mode === true) return 'bootloader';
55
+ if (features.initialized === false) return 'notInitialized';
56
+ if (features.initialized === true) return 'normal';
57
+ return 'unknown';
58
+ };
59
+
60
+ const normalizeVersions = (
61
+ features?: Features,
62
+ onekeyFeatures?: OnekeyFeatures
63
+ ): UnifiedDeviceInfoVersions => ({
64
+ firmware: firstVersion(
65
+ onekeyFeatures?.onekey_firmware_version,
66
+ versionArrayToString(getDeviceFirmwareVersion(features))
67
+ ),
68
+ bootloader: firstVersion(
69
+ onekeyFeatures?.onekey_boot_version,
70
+ versionArrayToString(getDeviceBootloaderVersion(features))
71
+ ),
72
+ board: firstVersion(
73
+ onekeyFeatures?.onekey_board_version,
74
+ versionArrayToString(features ? getDeviceBoardloaderVersion(features) : undefined)
75
+ ),
76
+ ble: firstVersion(
77
+ onekeyFeatures?.onekey_ble_version,
78
+ features?.onekey_ble_version,
79
+ features?.ble_ver,
80
+ versionArrayToString(features ? getDeviceBLEFirmwareVersion(features) : undefined)
81
+ ),
82
+ se01: firstVersion(onekeyFeatures?.onekey_se01_version, features?.onekey_se01_version),
83
+ se02: firstVersion(onekeyFeatures?.onekey_se02_version, features?.onekey_se02_version),
84
+ se03: firstVersion(onekeyFeatures?.onekey_se03_version, features?.onekey_se03_version),
85
+ se04: firstVersion(onekeyFeatures?.onekey_se04_version, features?.onekey_se04_version),
86
+ se01Boot: firstVersion(
87
+ onekeyFeatures?.onekey_se01_boot_version,
88
+ features?.onekey_se01_boot_version
89
+ ),
90
+ se02Boot: firstVersion(
91
+ onekeyFeatures?.onekey_se02_boot_version,
92
+ features?.onekey_se02_boot_version
93
+ ),
94
+ se03Boot: firstVersion(
95
+ onekeyFeatures?.onekey_se03_boot_version,
96
+ features?.onekey_se03_boot_version
97
+ ),
98
+ se04Boot: firstVersion(
99
+ onekeyFeatures?.onekey_se04_boot_version,
100
+ features?.onekey_se04_boot_version
101
+ ),
102
+ });
103
+
104
+ const normalizeStatus = (protocol: DeviceInfoProtocol, features?: Features): DeviceInfoStatus => ({
105
+ mode: getDeviceMode(features),
106
+ initialized: features?.initialized ?? null,
107
+ bootloaderMode: features?.bootloader_mode ?? null,
108
+ unlocked: protocol === 'V2' ? null : features?.unlocked ?? null,
109
+ passphraseProtection: features?.passphrase_protection ?? null,
110
+ backupRequired: features?.needs_backup ?? null,
111
+ language: features?.language ?? null,
112
+ bleEnabled: (features as { ble_enable?: boolean } | undefined)?.ble_enable ?? null,
113
+ });
114
+
115
+ const normalizeVerify = (
116
+ features?: Features,
117
+ onekeyFeatures?: OnekeyFeatures
118
+ ): UnifiedDeviceInfoVerify => {
119
+ const featureRecord = features as Record<string, string | undefined> | undefined;
120
+ return {
121
+ firmwareBuildId: onekeyFeatures?.onekey_firmware_build_id ?? features?.onekey_firmware_build_id,
122
+ firmwareHash: onekeyFeatures?.onekey_firmware_hash ?? features?.onekey_firmware_hash,
123
+ bootloaderBuildId: onekeyFeatures?.onekey_boot_build_id ?? features?.onekey_boot_build_id,
124
+ bootloaderHash: onekeyFeatures?.onekey_boot_hash ?? features?.onekey_boot_hash,
125
+ boardBuildId: onekeyFeatures?.onekey_board_build_id ?? featureRecord?.onekey_board_build_id,
126
+ boardHash: onekeyFeatures?.onekey_board_hash ?? features?.onekey_board_hash,
127
+ bleBuildId: onekeyFeatures?.onekey_ble_build_id ?? features?.onekey_ble_build_id,
128
+ bleHash: onekeyFeatures?.onekey_ble_hash ?? features?.onekey_ble_hash,
129
+ se01BuildId: onekeyFeatures?.onekey_se01_build_id ?? features?.onekey_se01_build_id,
130
+ se01Hash: onekeyFeatures?.onekey_se01_hash ?? featureRecord?.onekey_se01_hash,
131
+ se02BuildId: onekeyFeatures?.onekey_se02_build_id ?? featureRecord?.onekey_se02_build_id,
132
+ se02Hash: onekeyFeatures?.onekey_se02_hash ?? featureRecord?.onekey_se02_hash,
133
+ se03BuildId: onekeyFeatures?.onekey_se03_build_id ?? featureRecord?.onekey_se03_build_id,
134
+ se03Hash: onekeyFeatures?.onekey_se03_hash ?? featureRecord?.onekey_se03_hash,
135
+ se04BuildId: onekeyFeatures?.onekey_se04_build_id ?? featureRecord?.onekey_se04_build_id,
136
+ se04Hash: onekeyFeatures?.onekey_se04_hash ?? featureRecord?.onekey_se04_hash,
137
+ se01BootBuildId:
138
+ onekeyFeatures?.onekey_se01_boot_build_id ?? features?.onekey_se01_boot_build_id,
139
+ se01BootHash: onekeyFeatures?.onekey_se01_boot_hash ?? features?.onekey_se01_boot_hash,
140
+ se02BootBuildId:
141
+ onekeyFeatures?.onekey_se02_boot_build_id ?? features?.onekey_se02_boot_build_id,
142
+ se02BootHash: onekeyFeatures?.onekey_se02_boot_hash ?? features?.onekey_se02_boot_hash,
143
+ se03BootBuildId:
144
+ onekeyFeatures?.onekey_se03_boot_build_id ?? features?.onekey_se03_boot_build_id,
145
+ se03BootHash: onekeyFeatures?.onekey_se03_boot_hash ?? features?.onekey_se03_boot_hash,
146
+ se04BootBuildId:
147
+ onekeyFeatures?.onekey_se04_boot_build_id ?? features?.onekey_se04_boot_build_id,
148
+ se04BootHash: onekeyFeatures?.onekey_se04_boot_hash ?? features?.onekey_se04_boot_hash,
149
+ };
150
+ };
151
+
152
+ const normalizeRaw = ({
153
+ features,
154
+ onekeyFeatures,
155
+ protocolV2DeviceInfo,
156
+ }: Pick<
157
+ BuildDeviceInfoParams,
158
+ 'features' | 'onekeyFeatures' | 'protocolV2DeviceInfo'
159
+ >): UnifiedDeviceInfoRaw => ({
160
+ ...(features ? { features } : {}),
161
+ ...(onekeyFeatures ? { onekeyFeatures } : {}),
162
+ ...(protocolV2DeviceInfo ? { protocolV2DeviceInfo } : {}),
163
+ });
164
+
165
+ export function buildUnifiedDeviceInfo({
166
+ protocol,
167
+ features,
168
+ onekeyFeatures,
169
+ protocolV2DeviceInfo,
170
+ sources,
171
+ scope = 'basic',
172
+ includeRaw = false,
173
+ }: BuildDeviceInfoParams): UnifiedDeviceInfo {
174
+ const mergedFeatures = {
175
+ ...(features ?? {}),
176
+ ...(onekeyFeatures ?? {}),
177
+ } as Features;
178
+ const hasFeatures = Boolean(features || onekeyFeatures);
179
+ const sourceFeatures = hasFeatures ? mergedFeatures : undefined;
180
+ const deviceType = getDeviceType(sourceFeatures);
181
+ const verify = normalizeVerify(sourceFeatures, onekeyFeatures);
182
+
183
+ return {
184
+ protocol,
185
+ sources,
186
+ deviceType,
187
+ firmwareType: getFirmwareType(sourceFeatures),
188
+ deviceId: sourceFeatures?.device_id || safeGetDeviceUUID(sourceFeatures),
189
+ serialNo: safeGetDeviceUUID(sourceFeatures),
190
+ label: getDeviceLabel(sourceFeatures),
191
+ bleName: getDeviceBleName(sourceFeatures),
192
+ status: normalizeStatus(protocol, sourceFeatures),
193
+ versions: normalizeVersions(sourceFeatures, onekeyFeatures),
194
+ ...(shouldIncludeVerify(scope) ? { verify } : {}),
195
+ ...(includeRaw
196
+ ? {
197
+ raw: normalizeRaw({
198
+ features,
199
+ onekeyFeatures,
200
+ protocolV2DeviceInfo,
201
+ }),
202
+ }
203
+ : {}),
204
+ };
205
+ }