@onekeyfe/hd-core 1.1.27 → 1.2.0-alpha.0

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 (377) 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 +3025 -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.map +1 -1
  29. package/dist/api/GetOnekeyFeatures.d.ts.map +1 -1
  30. package/dist/api/GetPassphraseState.d.ts +6 -1
  31. package/dist/api/GetPassphraseState.d.ts.map +1 -1
  32. package/dist/api/PathInfo.d.ts +10 -0
  33. package/dist/api/PathInfo.d.ts.map +1 -0
  34. package/dist/api/PromptWebDeviceAccess.d.ts.map +1 -1
  35. package/dist/api/SearchDevices.d.ts +2 -1
  36. package/dist/api/SearchDevices.d.ts.map +1 -1
  37. package/dist/api/alephium/AlephiumGetAddress.d.ts +2 -6
  38. package/dist/api/alephium/AlephiumGetAddress.d.ts.map +1 -1
  39. package/dist/api/alephium/AlephiumSignMessage.d.ts +2 -5
  40. package/dist/api/alephium/AlephiumSignMessage.d.ts.map +1 -1
  41. package/dist/api/alephium/AlephiumSignTransaction.d.ts +5 -8
  42. package/dist/api/alephium/AlephiumSignTransaction.d.ts.map +1 -1
  43. package/dist/api/aptos/AptosGetAddress.d.ts.map +1 -1
  44. package/dist/api/benfen/BenfenGetAddress.d.ts +2 -9
  45. package/dist/api/benfen/BenfenGetAddress.d.ts.map +1 -1
  46. package/dist/api/benfen/BenfenGetPublicKey.d.ts +2 -9
  47. package/dist/api/benfen/BenfenGetPublicKey.d.ts.map +1 -1
  48. package/dist/api/benfen/BenfenSignMessage.d.ts +2 -8
  49. package/dist/api/benfen/BenfenSignMessage.d.ts.map +1 -1
  50. package/dist/api/benfen/BenfenSignTransaction.d.ts +2 -8
  51. package/dist/api/benfen/BenfenSignTransaction.d.ts.map +1 -1
  52. package/dist/api/btc/BTCGetAddress.d.ts +1 -11
  53. package/dist/api/btc/BTCGetAddress.d.ts.map +1 -1
  54. package/dist/api/btc/BTCGetPublicKey.d.ts +1 -11
  55. package/dist/api/btc/BTCGetPublicKey.d.ts.map +1 -1
  56. package/dist/api/btc/BTCSignMessage.d.ts +1 -15
  57. package/dist/api/btc/BTCSignMessage.d.ts.map +1 -1
  58. package/dist/api/btc/BTCSignPsbt.d.ts.map +1 -1
  59. package/dist/api/btc/BTCSignTransaction.d.ts +1 -11
  60. package/dist/api/btc/BTCSignTransaction.d.ts.map +1 -1
  61. package/dist/api/btc/BTCVerifyMessage.d.ts +1 -11
  62. package/dist/api/btc/BTCVerifyMessage.d.ts.map +1 -1
  63. package/dist/api/btc/helpers/versionLimit.d.ts +2 -11
  64. package/dist/api/btc/helpers/versionLimit.d.ts.map +1 -1
  65. package/dist/api/cardano/CardanoSignTransaction.d.ts.map +1 -1
  66. package/dist/api/conflux/ConfluxSignTransaction.d.ts.map +1 -1
  67. package/dist/api/device/DeviceLock.d.ts.map +1 -1
  68. package/dist/api/device/DeviceRebootToBoardloader.d.ts +1 -1
  69. package/dist/api/device/DeviceRebootToBoardloader.d.ts.map +1 -1
  70. package/dist/api/device/DeviceRebootToBootloader.d.ts.map +1 -1
  71. package/dist/api/device/DeviceSupportFeatures.d.ts.map +1 -1
  72. package/dist/api/device/DeviceUploadResource.d.ts.map +1 -1
  73. package/dist/api/device/DeviceVerify.d.ts.map +1 -1
  74. package/dist/api/dynex/DnxGetAddress.d.ts.map +1 -1
  75. package/dist/api/dynex/DnxSignTransaction.d.ts.map +1 -1
  76. package/dist/api/evm/EVMGetPublicKey.d.ts.map +1 -1
  77. package/dist/api/evm/EVMSignMessageEIP712.d.ts +2 -8
  78. package/dist/api/evm/EVMSignMessageEIP712.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/latest/signTypedHash.d.ts.map +1 -1
  83. package/dist/api/evm/legacyV1/getAddress.d.ts.map +1 -1
  84. package/dist/api/evm/legacyV1/getPublicKey.d.ts.map +1 -1
  85. package/dist/api/evm/legacyV1/signMessage.d.ts.map +1 -1
  86. package/dist/api/evm/legacyV1/signTypedData.d.ts +1 -1
  87. package/dist/api/evm/legacyV1/signTypedData.d.ts.map +1 -1
  88. package/dist/api/evm/legacyV1/signTypedHash.d.ts.map +1 -1
  89. package/dist/api/evm/legacyV1/verifyMessage.d.ts.map +1 -1
  90. package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
  91. package/dist/api/helpers/batchGetPublickeys.d.ts +3 -0
  92. package/dist/api/helpers/batchGetPublickeys.d.ts.map +1 -1
  93. package/dist/api/helpers/filesystemValidation.d.ts +7 -0
  94. package/dist/api/helpers/filesystemValidation.d.ts.map +1 -0
  95. package/dist/api/index.d.ts +32 -0
  96. package/dist/api/index.d.ts.map +1 -1
  97. package/dist/api/kaspa/KaspaSignTransaction.d.ts.map +1 -1
  98. package/dist/api/lightning/LnurlAuth.d.ts +4 -0
  99. package/dist/api/lightning/LnurlAuth.d.ts.map +1 -1
  100. package/dist/api/neo/NeoGetAddress.d.ts +2 -8
  101. package/dist/api/neo/NeoGetAddress.d.ts.map +1 -1
  102. package/dist/api/neo/NeoSignTransaction.d.ts +2 -8
  103. package/dist/api/neo/NeoSignTransaction.d.ts.map +1 -1
  104. package/dist/api/nervos/NervosGetAddress.d.ts +2 -9
  105. package/dist/api/nervos/NervosGetAddress.d.ts.map +1 -1
  106. package/dist/api/nervos/NervosSignTransaction.d.ts +9 -12
  107. package/dist/api/nervos/NervosSignTransaction.d.ts.map +1 -1
  108. package/dist/api/nexa/NexaGetAddress.d.ts +2 -8
  109. package/dist/api/nexa/NexaGetAddress.d.ts.map +1 -1
  110. package/dist/api/nexa/NexaSignTransaction.d.ts +2 -9
  111. package/dist/api/nexa/NexaSignTransaction.d.ts.map +1 -1
  112. package/dist/api/polkadot/PolkadotGetAddress.d.ts +3 -0
  113. package/dist/api/polkadot/PolkadotGetAddress.d.ts.map +1 -1
  114. package/dist/api/polkadot/networks.d.ts +3 -0
  115. package/dist/api/polkadot/networks.d.ts.map +1 -1
  116. package/dist/api/protocol-v2/DevReboot.d.ts +7 -0
  117. package/dist/api/protocol-v2/DevReboot.d.ts.map +1 -0
  118. package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts +7 -0
  119. package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts.map +1 -0
  120. package/dist/api/protocol-v2/DeviceGetDeviceInfo.d.ts +29 -0
  121. package/dist/api/protocol-v2/DeviceGetDeviceInfo.d.ts.map +1 -0
  122. package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts +6 -0
  123. package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts.map +1 -0
  124. package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts +6 -0
  125. package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts.map +1 -0
  126. package/dist/api/protocol-v2/DeviceReboot.d.ts +7 -0
  127. package/dist/api/protocol-v2/DeviceReboot.d.ts.map +1 -0
  128. package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts +7 -0
  129. package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts.map +1 -0
  130. package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts +6 -0
  131. package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts.map +1 -0
  132. package/dist/api/protocol-v2/FilesystemDiskControl.d.ts +13 -0
  133. package/dist/api/protocol-v2/FilesystemDiskControl.d.ts.map +1 -0
  134. package/dist/api/protocol-v2/FilesystemFixPermission.d.ts +6 -0
  135. package/dist/api/protocol-v2/FilesystemFixPermission.d.ts.map +1 -0
  136. package/dist/api/protocol-v2/FilesystemFormat.d.ts +6 -0
  137. package/dist/api/protocol-v2/FilesystemFormat.d.ts.map +1 -0
  138. package/dist/api/protocol-v2/GetProtoVersion.d.ts +6 -0
  139. package/dist/api/protocol-v2/GetProtoVersion.d.ts.map +1 -0
  140. package/dist/api/protocol-v2/Ping.d.ts +8 -0
  141. package/dist/api/protocol-v2/Ping.d.ts.map +1 -0
  142. package/dist/api/protocol-v2/helpers.d.ts +34 -0
  143. package/dist/api/protocol-v2/helpers.d.ts.map +1 -0
  144. package/dist/api/scdo/ScdoGetAddress.d.ts +2 -6
  145. package/dist/api/scdo/ScdoGetAddress.d.ts.map +1 -1
  146. package/dist/api/scdo/ScdoSignMessage.d.ts +2 -5
  147. package/dist/api/scdo/ScdoSignMessage.d.ts.map +1 -1
  148. package/dist/api/scdo/ScdoSignTransaction.d.ts +2 -5
  149. package/dist/api/scdo/ScdoSignTransaction.d.ts.map +1 -1
  150. package/dist/api/solana/SolGetAddress.d.ts +1 -0
  151. package/dist/api/solana/SolGetAddress.d.ts.map +1 -1
  152. package/dist/api/solana/SolSignMessage.d.ts +3 -0
  153. package/dist/api/solana/SolSignMessage.d.ts.map +1 -1
  154. package/dist/api/solana/SolSignOffchainMessage.d.ts +3 -0
  155. package/dist/api/solana/SolSignOffchainMessage.d.ts.map +1 -1
  156. package/dist/api/solana/SolSignTransaction.d.ts +6 -0
  157. package/dist/api/solana/SolSignTransaction.d.ts.map +1 -1
  158. package/dist/api/stellar/StellarGetAddress.d.ts +2 -1
  159. package/dist/api/stellar/StellarGetAddress.d.ts.map +1 -1
  160. package/dist/api/stellar/StellarSignTransaction.d.ts +3 -2
  161. package/dist/api/stellar/StellarSignTransaction.d.ts.map +1 -1
  162. package/dist/api/sui/SuiGetAddress.d.ts +3 -0
  163. package/dist/api/sui/SuiGetAddress.d.ts.map +1 -1
  164. package/dist/api/sui/SuiGetPublicKey.d.ts +3 -0
  165. package/dist/api/sui/SuiGetPublicKey.d.ts.map +1 -1
  166. package/dist/api/sui/SuiSignMessage.d.ts +3 -0
  167. package/dist/api/sui/SuiSignMessage.d.ts.map +1 -1
  168. package/dist/api/sui/SuiSignTransaction.d.ts +5 -2
  169. package/dist/api/sui/SuiSignTransaction.d.ts.map +1 -1
  170. package/dist/api/ton/TonGetAddress.d.ts +3 -0
  171. package/dist/api/ton/TonGetAddress.d.ts.map +1 -1
  172. package/dist/api/ton/TonSignData.d.ts +5 -0
  173. package/dist/api/ton/TonSignData.d.ts.map +1 -1
  174. package/dist/api/ton/TonSignMessage.d.ts +3 -0
  175. package/dist/api/ton/TonSignMessage.d.ts.map +1 -1
  176. package/dist/api/ton/TonSignProof.d.ts +3 -0
  177. package/dist/api/ton/TonSignProof.d.ts.map +1 -1
  178. package/dist/api/tron/TronSignMessage.d.ts +4 -0
  179. package/dist/api/tron/TronSignMessage.d.ts.map +1 -1
  180. package/dist/api/tron/TronSignTransaction.d.ts +4 -0
  181. package/dist/api/tron/TronSignTransaction.d.ts.map +1 -1
  182. package/dist/core/index.d.ts.map +1 -1
  183. package/dist/data-manager/DataManager.d.ts +7 -4
  184. package/dist/data-manager/DataManager.d.ts.map +1 -1
  185. package/dist/data-manager/MessagesConfig.d.ts +2 -2
  186. package/dist/data-manager/MessagesConfig.d.ts.map +1 -1
  187. package/dist/data-manager/TransportManager.d.ts +5 -4
  188. package/dist/data-manager/TransportManager.d.ts.map +1 -1
  189. package/dist/device/Device.d.ts +36 -10
  190. package/dist/device/Device.d.ts.map +1 -1
  191. package/dist/device/DeviceCommands.d.ts +9 -9
  192. package/dist/device/DeviceCommands.d.ts.map +1 -1
  193. package/dist/device/DeviceConnector.d.ts +2 -1
  194. package/dist/device/DeviceConnector.d.ts.map +1 -1
  195. package/dist/deviceProfile/buildDeviceProfile.d.ts +22 -0
  196. package/dist/deviceProfile/buildDeviceProfile.d.ts.map +1 -0
  197. package/dist/deviceProfile/index.d.ts +3 -0
  198. package/dist/deviceProfile/index.d.ts.map +1 -0
  199. package/dist/deviceProfile/legacyFeaturesView.d.ts +5 -0
  200. package/dist/deviceProfile/legacyFeaturesView.d.ts.map +1 -0
  201. package/dist/events/logBlockEvent.d.ts +1 -0
  202. package/dist/events/logBlockEvent.d.ts.map +1 -1
  203. package/dist/events/ui-request.d.ts +8 -0
  204. package/dist/events/ui-request.d.ts.map +1 -1
  205. package/dist/index.d.ts +720 -382
  206. package/dist/index.js +17634 -1201
  207. package/dist/inject.d.ts.map +1 -1
  208. package/dist/protocols/protocol-v2/features.d.ts +93 -0
  209. package/dist/protocols/protocol-v2/features.d.ts.map +1 -0
  210. package/dist/protocols/protocol-v2/firmware.d.ts +13 -0
  211. package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -0
  212. package/dist/protocols/protocol-v2/index.d.ts +4 -0
  213. package/dist/protocols/protocol-v2/index.d.ts.map +1 -0
  214. package/dist/types/api/export.d.ts +1 -1
  215. package/dist/types/api/export.d.ts.map +1 -1
  216. package/dist/types/api/firmwareUpdate.d.ts +27 -0
  217. package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
  218. package/dist/types/api/getDeviceInfo.d.ts +85 -0
  219. package/dist/types/api/getDeviceInfo.d.ts.map +1 -0
  220. package/dist/types/api/getPassphraseState.d.ts +10 -1
  221. package/dist/types/api/getPassphraseState.d.ts.map +1 -1
  222. package/dist/types/api/index.d.ts +37 -1
  223. package/dist/types/api/index.d.ts.map +1 -1
  224. package/dist/types/api/protocolV2.d.ts +103 -0
  225. package/dist/types/api/protocolV2.d.ts.map +1 -0
  226. package/dist/types/api/searchDevices.d.ts +2 -2
  227. package/dist/types/api/searchDevices.d.ts.map +1 -1
  228. package/dist/types/device.d.ts +10 -3
  229. package/dist/types/device.d.ts.map +1 -1
  230. package/dist/types/params.d.ts +2 -0
  231. package/dist/types/params.d.ts.map +1 -1
  232. package/dist/types/settings.d.ts +1 -1
  233. package/dist/types/settings.d.ts.map +1 -1
  234. package/dist/utils/deviceFeaturesUtils.d.ts +6 -8
  235. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  236. package/dist/utils/deviceInfoUtils.d.ts +1 -0
  237. package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
  238. package/dist/utils/index.d.ts +1 -1
  239. package/dist/utils/index.d.ts.map +1 -1
  240. package/dist/utils/patch.d.ts +1 -1
  241. package/dist/utils/patch.d.ts.map +1 -1
  242. package/package.json +4 -4
  243. package/src/api/BaseMethod.ts +26 -22
  244. package/src/api/DirList.ts +31 -0
  245. package/src/api/DirMake.ts +23 -0
  246. package/src/api/DirRemove.ts +23 -0
  247. package/src/api/FileDelete.ts +23 -0
  248. package/src/api/FileRead.ts +167 -0
  249. package/src/api/FileWrite.ts +216 -0
  250. package/src/api/FirmwareUpdate.ts +13 -5
  251. package/src/api/FirmwareUpdateV2.ts +21 -25
  252. package/src/api/FirmwareUpdateV3.ts +17 -4
  253. package/src/api/FirmwareUpdateV4.ts +827 -0
  254. package/src/api/GetDeviceInfo.ts +152 -0
  255. package/src/api/GetFeatures.ts +5 -2
  256. package/src/api/GetOnekeyFeatures.ts +95 -3
  257. package/src/api/GetPassphraseState.ts +16 -10
  258. package/src/api/PathInfo.ts +39 -0
  259. package/src/api/PromptWebDeviceAccess.ts +11 -1
  260. package/src/api/SearchDevices.ts +7 -2
  261. package/src/api/alephium/AlephiumGetAddress.ts +6 -2
  262. package/src/api/alephium/AlephiumSignMessage.ts +6 -1
  263. package/src/api/alephium/AlephiumSignTransaction.ts +15 -4
  264. package/src/api/allnetwork/AllNetworkGetAddressBase.ts +21 -13
  265. package/src/api/aptos/AptosGetAddress.ts +2 -3
  266. package/src/api/benfen/BenfenGetAddress.ts +11 -7
  267. package/src/api/benfen/BenfenGetPublicKey.ts +6 -2
  268. package/src/api/benfen/BenfenSignMessage.ts +6 -1
  269. package/src/api/benfen/BenfenSignTransaction.ts +6 -1
  270. package/src/api/btc/BTCGetPublicKey.ts +3 -2
  271. package/src/api/btc/BTCSignPsbt.ts +1 -2
  272. package/src/api/btc/helpers/versionLimit.ts +7 -1
  273. package/src/api/cardano/CardanoSignTransaction.ts +2 -4
  274. package/src/api/conflux/ConfluxSignTransaction.ts +5 -2
  275. package/src/api/device/DeviceFullyUploadResource.ts +3 -3
  276. package/src/api/device/DeviceLock.ts +1 -3
  277. package/src/api/device/DeviceRebootToBoardloader.ts +10 -1
  278. package/src/api/device/DeviceRebootToBootloader.ts +10 -1
  279. package/src/api/device/DeviceSupportFeatures.ts +2 -13
  280. package/src/api/device/DeviceUpdateBootloader.ts +4 -4
  281. package/src/api/device/DeviceUploadResource.ts +4 -5
  282. package/src/api/device/DeviceVerify.ts +1 -2
  283. package/src/api/dynex/DnxGetAddress.ts +6 -0
  284. package/src/api/dynex/DnxSignTransaction.ts +6 -0
  285. package/src/api/evm/EVMGetAddress.ts +1 -1
  286. package/src/api/evm/EVMGetPublicKey.ts +3 -4
  287. package/src/api/evm/EVMSignMessage.ts +1 -1
  288. package/src/api/evm/EVMSignMessageEIP712.ts +14 -1
  289. package/src/api/evm/EVMSignTransaction.ts +1 -1
  290. package/src/api/evm/EVMSignTypedData.ts +32 -18
  291. package/src/api/evm/EVMVerifyMessage.ts +1 -1
  292. package/src/api/evm/latest/signTypedHash.ts +2 -4
  293. package/src/api/evm/legacyV1/getAddress.ts +5 -3
  294. package/src/api/evm/legacyV1/getPublicKey.ts +5 -3
  295. package/src/api/evm/legacyV1/signMessage.ts +5 -3
  296. package/src/api/evm/legacyV1/signTypedData.ts +9 -8
  297. package/src/api/evm/legacyV1/signTypedHash.ts +7 -7
  298. package/src/api/evm/legacyV1/verifyMessage.ts +5 -3
  299. package/src/api/firmware/FirmwareUpdateBaseMethod.ts +8 -8
  300. package/src/api/firmware/uploadFirmware.ts +3 -10
  301. package/src/api/helpers/batchGetPublickeys.ts +51 -6
  302. package/src/api/helpers/filesystemValidation.ts +51 -0
  303. package/src/api/index.ts +34 -0
  304. package/src/api/kaspa/KaspaSignTransaction.ts +4 -5
  305. package/src/api/lightning/LnurlAuth.ts +4 -0
  306. package/src/api/neo/NeoGetAddress.ts +6 -1
  307. package/src/api/neo/NeoSignTransaction.ts +6 -1
  308. package/src/api/nervos/NervosGetAddress.ts +6 -2
  309. package/src/api/nervos/NervosSignTransaction.ts +14 -4
  310. package/src/api/nexa/NexaGetAddress.ts +6 -2
  311. package/src/api/nexa/NexaSignTransaction.ts +11 -12
  312. package/src/api/polkadot/networks.ts +9 -0
  313. package/src/api/protocol-v2/DevReboot.ts +24 -0
  314. package/src/api/protocol-v2/DeviceFirmwareUpdate.ts +63 -0
  315. package/src/api/protocol-v2/DeviceGetDeviceInfo.ts +118 -0
  316. package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +20 -0
  317. package/src/api/protocol-v2/DeviceGetOnboardingStatus.ts +16 -0
  318. package/src/api/protocol-v2/DeviceReboot.ts +24 -0
  319. package/src/api/protocol-v2/FactoryDeviceInfoSettings.ts +29 -0
  320. package/src/api/protocol-v2/FactoryGetDeviceInfo.ts +20 -0
  321. package/src/api/protocol-v2/FilesystemDiskControl.ts +50 -0
  322. package/src/api/protocol-v2/FilesystemFixPermission.ts +16 -0
  323. package/src/api/protocol-v2/FilesystemFormat.ts +16 -0
  324. package/src/api/protocol-v2/GetProtoVersion.ts +16 -0
  325. package/src/api/protocol-v2/Ping.ts +18 -0
  326. package/src/api/protocol-v2/helpers.ts +207 -0
  327. package/src/api/scdo/ScdoGetAddress.ts +6 -2
  328. package/src/api/scdo/ScdoSignMessage.ts +6 -1
  329. package/src/api/scdo/ScdoSignTransaction.ts +6 -2
  330. package/src/api/solana/SolGetAddress.ts +4 -0
  331. package/src/api/solana/SolSignMessage.ts +3 -0
  332. package/src/api/solana/SolSignOffchainMessage.ts +3 -0
  333. package/src/api/solana/SolSignTransaction.ts +6 -0
  334. package/src/api/stellar/StellarGetAddress.ts +10 -1
  335. package/src/api/stellar/StellarSignTransaction.ts +14 -1
  336. package/src/api/sui/SuiGetAddress.ts +5 -3
  337. package/src/api/sui/SuiGetPublicKey.ts +3 -0
  338. package/src/api/sui/SuiSignMessage.ts +3 -0
  339. package/src/api/sui/SuiSignTransaction.ts +14 -12
  340. package/src/api/ton/TonGetAddress.ts +3 -0
  341. package/src/api/ton/TonSignData.ts +10 -3
  342. package/src/api/ton/TonSignMessage.ts +6 -5
  343. package/src/api/ton/TonSignProof.ts +3 -0
  344. package/src/api/tron/TronSignMessage.ts +5 -1
  345. package/src/api/tron/TronSignTransaction.ts +4 -0
  346. package/src/api/xrp/XrpSignTransaction.ts +1 -1
  347. package/src/core/index.ts +87 -55
  348. package/src/data/messages/messages-protocol-v2.json +13369 -0
  349. package/src/data-manager/DataManager.ts +12 -7
  350. package/src/data-manager/MessagesConfig.ts +14 -14
  351. package/src/data-manager/TransportManager.ts +38 -12
  352. package/src/device/Device.ts +538 -61
  353. package/src/device/DeviceCommands.ts +195 -29
  354. package/src/device/DeviceConnector.ts +29 -4
  355. package/src/device/DevicePool.ts +7 -7
  356. package/src/deviceProfile/buildDeviceProfile.ts +387 -0
  357. package/src/deviceProfile/index.ts +2 -0
  358. package/src/deviceProfile/legacyFeaturesView.ts +123 -0
  359. package/src/events/logBlockEvent.ts +23 -0
  360. package/src/events/ui-request.ts +8 -0
  361. package/src/inject.ts +52 -1
  362. package/src/protocols/protocol-v2/features.ts +180 -0
  363. package/src/protocols/protocol-v2/firmware.ts +43 -0
  364. package/src/protocols/protocol-v2/index.ts +16 -0
  365. package/src/types/api/export.ts +1 -0
  366. package/src/types/api/firmwareUpdate.ts +49 -0
  367. package/src/types/api/getDeviceInfo.ts +99 -0
  368. package/src/types/api/getPassphraseState.ts +13 -2
  369. package/src/types/api/index.ts +88 -1
  370. package/src/types/api/protocolV2.ts +201 -0
  371. package/src/types/api/searchDevices.ts +2 -2
  372. package/src/types/device.ts +37 -3
  373. package/src/types/params.ts +7 -0
  374. package/src/types/settings.ts +1 -1
  375. package/src/utils/deviceFeaturesUtils.ts +70 -70
  376. package/src/utils/deviceInfoUtils.ts +15 -8
  377. package/src/utils/index.ts +1 -0
@@ -0,0 +1,152 @@
1
+ import semver from 'semver';
2
+ import { EDeviceType, ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
3
+
4
+ import { UI_REQUEST } from '../constants/ui-request';
5
+ import {
6
+ PROTOCOL_V2_DEVICE_INFO_REQUEST,
7
+ PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST,
8
+ PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST,
9
+ } from '../protocols/protocol-v2';
10
+ import { requestProtocolV2DeviceInfo } from '../protocols/protocol-v2/features';
11
+ import { buildProfileFromProtocolV1, buildProfileFromProtocolV2 } from '../deviceProfile';
12
+ import { getDeviceType } from '../utils';
13
+ import { fixVersion } from '../utils/deviceFeaturesUtils';
14
+ import { BaseMethod } from './BaseMethod';
15
+
16
+ import type {
17
+ DeviceInfoScope,
18
+ DeviceInfoSource,
19
+ GetDeviceInfoParams,
20
+ } from '../types/api/getDeviceInfo';
21
+ import type { Features, OnekeyFeatures } from '../types';
22
+
23
+ const DEVICE_INFO_SCOPES: readonly DeviceInfoScope[] = ['basic', 'versions', 'verify', 'full'];
24
+
25
+ function isDeviceInfoScope(scope: unknown): scope is DeviceInfoScope {
26
+ return typeof scope === 'string' && DEVICE_INFO_SCOPES.includes(scope as DeviceInfoScope);
27
+ }
28
+
29
+ function normalizeScope(scope: unknown): GetDeviceInfoParams['scope'] {
30
+ if (scope === undefined || scope === null) return 'basic';
31
+ if (isDeviceInfoScope(scope)) {
32
+ return scope;
33
+ }
34
+ throw ERRORS.TypedError(
35
+ HardwareErrorCode.CallMethodInvalidParameter,
36
+ `Invalid getDeviceInfo scope: ${String(scope)}`
37
+ );
38
+ }
39
+
40
+ function resolveProtocolV2DeviceInfoRequest(params: GetDeviceInfoParams) {
41
+ if (params.scope === 'verify' || params.scope === 'full') {
42
+ return PROTOCOL_V2_DEVICE_INFO_REQUEST;
43
+ }
44
+ if (params.scope === 'versions') {
45
+ return PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST;
46
+ }
47
+ return PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST;
48
+ }
49
+
50
+ function shouldReadOnekeyFeatures(params: GetDeviceInfoParams) {
51
+ return (
52
+ params.includeRaw === true ||
53
+ params.scope === 'versions' ||
54
+ params.scope === 'verify' ||
55
+ params.scope === 'full'
56
+ );
57
+ }
58
+
59
+ function supportOnekeyFeatures(features?: Features) {
60
+ if (!features || features.bootloader_mode) return false;
61
+
62
+ const deviceType = getDeviceType(features);
63
+ return ![
64
+ EDeviceType.Unknown,
65
+ EDeviceType.Classic1s,
66
+ EDeviceType.ClassicPure,
67
+ EDeviceType.Pro2,
68
+ ].includes(deviceType);
69
+ }
70
+
71
+ function normalizeOnekeyFeatures(message: OnekeyFeatures) {
72
+ if (message.onekey_firmware_version && !semver.valid(message.onekey_firmware_version)) {
73
+ message.onekey_firmware_version = fixVersion(message.onekey_firmware_version);
74
+ }
75
+ return message;
76
+ }
77
+
78
+ export default class GetDeviceInfo extends BaseMethod<GetDeviceInfoParams> {
79
+ init() {
80
+ this.allowDeviceMode = [
81
+ ...this.allowDeviceMode,
82
+ UI_REQUEST.NOT_INITIALIZE,
83
+ UI_REQUEST.BOOTLOADER,
84
+ ];
85
+ this.useDevicePassphraseState = false;
86
+ this.skipForceUpdateCheck = true;
87
+ this.params = {
88
+ scope: normalizeScope(this.payload.scope),
89
+ refresh: this.payload.refresh,
90
+ includeRaw: this.payload.includeRaw,
91
+ };
92
+ }
93
+
94
+ async run() {
95
+ if (this.device.isProtocolV2()) {
96
+ return this.runProtocolV2();
97
+ }
98
+ return this.runProtocolV1();
99
+ }
100
+
101
+ private async runProtocolV2() {
102
+ const sources: DeviceInfoSource[] = ['deviceInfo'];
103
+ const protocolV2DeviceInfo = await requestProtocolV2DeviceInfo({
104
+ commands: this.device.commands,
105
+ request: resolveProtocolV2DeviceInfoRequest(this.params),
106
+ });
107
+ const profile = buildProfileFromProtocolV2({
108
+ deviceInfo: protocolV2DeviceInfo,
109
+ sources,
110
+ scope: this.params.scope,
111
+ includeRaw: this.params.includeRaw,
112
+ fallbackSerialNo: this.device.originalDescriptor?.path,
113
+ });
114
+ // 缓存走字段级合并:basic 请求不能降级已有的完整 profile;返回值仍按请求 scope 给出
115
+ if (typeof this.device.applyProfileUpdate === 'function') {
116
+ this.device.applyProfileUpdate(profile, protocolV2DeviceInfo);
117
+ } else {
118
+ this.device.updateProfile?.(profile);
119
+ }
120
+ return profile;
121
+ }
122
+
123
+ private async runProtocolV1() {
124
+ if (this.params.refresh === true) {
125
+ await this.device.getFeatures();
126
+ }
127
+
128
+ const sources: DeviceInfoSource[] = ['features'];
129
+ const { features } = this.device;
130
+ let onekeyFeatures: OnekeyFeatures | undefined;
131
+
132
+ if (shouldReadOnekeyFeatures(this.params) && supportOnekeyFeatures(features)) {
133
+ const { message } = await this.device.commands.typedCall(
134
+ 'OnekeyGetFeatures',
135
+ 'OnekeyFeatures'
136
+ );
137
+ onekeyFeatures = normalizeOnekeyFeatures(message);
138
+ sources.push('onekeyFeatures');
139
+ }
140
+
141
+ const profile = buildProfileFromProtocolV1({
142
+ protocol: 'V1',
143
+ features,
144
+ onekeyFeatures,
145
+ sources,
146
+ scope: this.params.scope,
147
+ includeRaw: this.params.includeRaw,
148
+ });
149
+ this.device.updateProfile?.(profile);
150
+ return profile;
151
+ }
152
+ }
@@ -14,10 +14,13 @@ export default class GetFeatures extends BaseMethod {
14
14
  this.skipForceUpdateCheck = true;
15
15
  }
16
16
 
17
- run() {
18
- if (this.payload?.detectBootloaderDevice && this.device.features?.bootloader_mode) {
17
+ async run() {
18
+ if (this.payload?.detectBootloaderDevice && this.device.isBootloader()) {
19
19
  return Promise.reject(ERRORS.TypedError(HardwareErrorCode.DeviceDetectInBootloaderMode));
20
20
  }
21
+ if (this.device.isProtocolV2()) {
22
+ return this.device.getFeatures();
23
+ }
21
24
  return Promise.resolve(this.device.features);
22
25
  }
23
26
  }
@@ -2,8 +2,81 @@ import semver from 'semver';
2
2
 
3
3
  import { UI_REQUEST } from '../constants/ui-request';
4
4
  import { fixVersion } from '../utils/deviceFeaturesUtils';
5
+ import { PROTOCOL_V2_DEVICE_INFO_REQUEST } from '../protocols/protocol-v2';
6
+ import { requestProtocolV2DeviceInfo } from '../protocols/protocol-v2/features';
7
+ import { buildProfileFromProtocolV2, buildProtocolV2GetFeaturesPayload } from '../deviceProfile';
5
8
  import { BaseMethod } from './BaseMethod';
6
9
 
10
+ import type { OnekeyFeatures } from '../types';
11
+
12
+ const ONEKEY_FEATURE_KEYS: Array<keyof OnekeyFeatures> = [
13
+ 'onekey_device_type',
14
+ 'onekey_board_version',
15
+ 'onekey_boot_version',
16
+ 'onekey_firmware_version',
17
+ 'onekey_board_hash',
18
+ 'onekey_boot_hash',
19
+ 'onekey_firmware_hash',
20
+ 'onekey_board_build_id',
21
+ 'onekey_boot_build_id',
22
+ 'onekey_firmware_build_id',
23
+ 'onekey_serial_no',
24
+ 'onekey_ble_name',
25
+ 'onekey_ble_version',
26
+ 'onekey_ble_build_id',
27
+ 'onekey_ble_hash',
28
+ 'onekey_se_type',
29
+ 'onekey_se01_state',
30
+ 'onekey_se02_state',
31
+ 'onekey_se03_state',
32
+ 'onekey_se04_state',
33
+ 'onekey_se01_version',
34
+ 'onekey_se02_version',
35
+ 'onekey_se03_version',
36
+ 'onekey_se04_version',
37
+ 'onekey_se01_hash',
38
+ 'onekey_se02_hash',
39
+ 'onekey_se03_hash',
40
+ 'onekey_se04_hash',
41
+ 'onekey_se01_build_id',
42
+ 'onekey_se02_build_id',
43
+ 'onekey_se03_build_id',
44
+ 'onekey_se04_build_id',
45
+ 'onekey_se01_boot_version',
46
+ 'onekey_se02_boot_version',
47
+ 'onekey_se03_boot_version',
48
+ 'onekey_se04_boot_version',
49
+ 'onekey_se01_boot_hash',
50
+ 'onekey_se02_boot_hash',
51
+ 'onekey_se03_boot_hash',
52
+ 'onekey_se04_boot_hash',
53
+ 'onekey_se01_boot_build_id',
54
+ 'onekey_se02_boot_build_id',
55
+ 'onekey_se03_boot_build_id',
56
+ 'onekey_se04_boot_build_id',
57
+ ];
58
+
59
+ function normalizeOnekeyFirmwareVersion(message: OnekeyFeatures) {
60
+ if (message.onekey_firmware_version && !semver.valid(message.onekey_firmware_version)) {
61
+ message.onekey_firmware_version = fixVersion(message.onekey_firmware_version);
62
+ }
63
+ }
64
+
65
+ function pickOnekeyFeatures(features?: OnekeyFeatures | null): OnekeyFeatures {
66
+ const message: OnekeyFeatures = {};
67
+ if (!features) return message;
68
+
69
+ for (const key of ONEKEY_FEATURE_KEYS) {
70
+ const value = features[key];
71
+ if (value !== undefined && value !== null) {
72
+ (message as Record<string, unknown>)[key] = value;
73
+ }
74
+ }
75
+
76
+ normalizeOnekeyFirmwareVersion(message);
77
+ return message;
78
+ }
79
+
7
80
  export default class GetOnekeyFeatures extends BaseMethod {
8
81
  init() {
9
82
  this.allowDeviceMode = [
@@ -16,10 +89,29 @@ export default class GetOnekeyFeatures extends BaseMethod {
16
89
  }
17
90
 
18
91
  async run() {
19
- const { message } = await this.device.commands.typedCall('OnekeyGetFeatures', 'OnekeyFeatures');
20
- if (!!message.onekey_firmware_version && !semver.valid(message.onekey_firmware_version)) {
21
- message.onekey_firmware_version = fixVersion(message.onekey_firmware_version);
92
+ if (this.device.isProtocolV2()) {
93
+ // V2 没有 OnekeyGetFeatures 消息:
94
+ // 取完整 DevGetDeviceInfo(含 SE/hash/build_id)后写入 features 兼容视图。
95
+ const deviceInfo = await requestProtocolV2DeviceInfo({
96
+ commands: this.device.commands,
97
+ request: PROTOCOL_V2_DEVICE_INFO_REQUEST,
98
+ });
99
+ const profile = this.device.applyProfileUpdate(
100
+ buildProfileFromProtocolV2({
101
+ deviceInfo,
102
+ sources: ['deviceInfo'],
103
+ scope: 'verify',
104
+ fallbackSerialNo: this.device.originalDescriptor?.path,
105
+ }),
106
+ deviceInfo
107
+ );
108
+ return pickOnekeyFeatures(
109
+ buildProtocolV2GetFeaturesPayload(profile, deviceInfo) as OnekeyFeatures
110
+ );
22
111
  }
112
+
113
+ const { message } = await this.device.commands.typedCall('OnekeyGetFeatures', 'OnekeyFeatures');
114
+ normalizeOnekeyFirmwareVersion(message);
23
115
  return Promise.resolve(message);
24
116
  }
25
117
  }
@@ -1,4 +1,4 @@
1
- import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
1
+ import { EDeviceType } from '@onekeyfe/hd-shared';
2
2
 
3
3
  import { UI_REQUEST } from '../constants/ui-request';
4
4
  import { getPassphraseStateWithRefreshDeviceInfo } from '../utils/deviceFeaturesUtils';
@@ -11,18 +11,24 @@ export default class GetPassphraseState extends BaseMethod {
11
11
  }
12
12
 
13
13
  async run() {
14
- if (!this.device.features)
15
- return Promise.reject(ERRORS.TypedError(HardwareErrorCode.DeviceInitializeFailed));
16
-
17
- const { passphraseState } = await getPassphraseStateWithRefreshDeviceInfo(this.device);
14
+ const { passphraseState, newSession, unlockedAttachPin } =
15
+ await getPassphraseStateWithRefreshDeviceInfo(this.device, {
16
+ expectPassphraseState: this.payload.passphraseState,
17
+ onlyMainPin: this.payload.useEmptyPassphrase,
18
+ allowCreateAttachPin: this.payload.allowCreateAttachPin,
19
+ });
18
20
 
19
21
  const { features } = this.device;
22
+ const passphraseProtection = this.device.getCurrentPassphraseProtection() ?? null;
23
+ const deviceType = this.device.getCurrentDeviceType();
24
+ const isProSeries = deviceType === EDeviceType.Pro || deviceType === EDeviceType.Pro2;
20
25
 
21
26
  // refresh device info
22
- if (features && features.passphrase_protection === true) {
23
- return Promise.resolve(passphraseState);
24
- }
25
-
26
- return Promise.resolve(undefined);
27
+ return Promise.resolve({
28
+ passphrase_state: isProSeries || passphraseProtection === true ? passphraseState : undefined,
29
+ session_id: newSession ?? features?.session_id ?? undefined,
30
+ unlocked_attach_pin: unlockedAttachPin ?? features?.unlocked_attach_pin,
31
+ passphrase_protection: passphraseProtection,
32
+ });
27
33
  }
28
34
  }
@@ -0,0 +1,39 @@
1
+ import { BaseMethod } from './BaseMethod';
2
+ import {
3
+ validateNonEmptyString,
4
+ validateOptionalNonNegativeInteger,
5
+ } from './helpers/filesystemValidation';
6
+
7
+ export type PathInfoParams = {
8
+ path: string;
9
+ timeoutMs?: number | string;
10
+ };
11
+
12
+ export default class PathInfo extends BaseMethod<PathInfoParams> {
13
+ init() {
14
+ // Protocol V2 (Pro2) 专属方法,core 调度层统一做非 V2 设备守卫
15
+ this.requireProtocolV2 = true;
16
+ this.skipForceUpdateCheck = true;
17
+ this.useDevicePassphraseState = false;
18
+ this.params = {
19
+ path: validateNonEmptyString(this.payload.path, 'path'),
20
+ timeoutMs: validateOptionalNonNegativeInteger(this.payload.timeoutMs, 'timeoutMs'),
21
+ };
22
+ }
23
+
24
+ async run() {
25
+ const timeoutMs =
26
+ this.params.timeoutMs === undefined ? undefined : Number(this.params.timeoutMs);
27
+ const res = await this.device.commands.typedCall(
28
+ 'FilesystemPathInfoQuery',
29
+ 'FilesystemPathInfo',
30
+ {
31
+ path: this.params.path,
32
+ },
33
+ {
34
+ timeoutMs,
35
+ }
36
+ );
37
+ return Promise.resolve(res.message);
38
+ }
39
+ }
@@ -51,9 +51,19 @@ export default class PromptWebDeviceAccess extends BaseMethod {
51
51
  }
52
52
 
53
53
  if (isWebUsbEnv) {
54
+ const usbDevice = device as USBDevice;
55
+ let path = usbDevice.serialNumber ?? '';
56
+ if (!path) {
57
+ // 早期 Pro2 工程板 USB descriptor 没有 serial number。
58
+ // 授权后重新枚举,transport 会为空 serial 设备生成会话内稳定的 mock path,
59
+ // 这里按 USBDevice 对象身份找回该 path,保证后续 acquire 能匹配。
60
+ const diff = await this.connector?.enumerate();
61
+ const matched = diff?.descriptors?.find(d => (d as any).device === usbDevice);
62
+ path = matched?.path ?? '';
63
+ }
54
64
  devicesDescriptor = [
55
65
  {
56
- path: (device as USBDevice).serialNumber ?? '',
66
+ path,
57
67
  device,
58
68
  debug: true,
59
69
  },
@@ -34,17 +34,22 @@ export default class SearchDevices extends BaseMethod {
34
34
  const lowerId = device.id?.toLowerCase();
35
35
  if (!seenIds.has(lowerId)) {
36
36
  seenIds.add(lowerId);
37
+ const bleName =
38
+ device.name ?? (device as unknown as { localName?: string }).localName ?? '';
37
39
  devices.push({
38
40
  ...device,
39
41
  connectId: device.id,
40
- deviceType: getDeviceTypeByBleName(device.name ?? ''),
42
+ name: bleName || device.name,
43
+ deviceType: getDeviceTypeByBleName(bleName),
41
44
  });
42
45
  }
43
46
  }
44
47
  return devices;
45
48
  }
46
49
 
47
- const { deviceList } = await DevicePool.getDevices(devicesDescriptor);
50
+ const { deviceList } = await DevicePool.getDevices(devicesDescriptor, undefined, {
51
+ connectProtocol: this.payload.connectProtocol,
52
+ });
48
53
  return deviceList.map(device => device.toMessageObject());
49
54
  }
50
55
  }
@@ -4,7 +4,7 @@ import { BaseMethod } from '../BaseMethod';
4
4
  import { validateParams, validateResult } from '../helpers/paramsValidator';
5
5
 
6
6
  import type { AlephiumGetAddress as HardwareAlephiumGetAddress } from '@onekeyfe/hd-transport';
7
- import type { AlephiumAddress, AlephiumGetAddressParams } from '../../types';
7
+ import type { AlephiumAddress, AlephiumGetAddressParams, DeviceFirmwareRange } from '../../types';
8
8
 
9
9
  export default class AlephiumGetAddress extends BaseMethod<HardwareAlephiumGetAddress[]> {
10
10
  hasBundle = false;
@@ -43,8 +43,12 @@ export default class AlephiumGetAddress extends BaseMethod<HardwareAlephiumGetAd
43
43
  });
44
44
  }
45
45
 
46
- getVersionRange() {
46
+ getVersionRange(): DeviceFirmwareRange {
47
47
  return {
48
+ pro2: {
49
+ min: '0.0.0',
50
+ unsupported: true,
51
+ },
48
52
  model_touch: {
49
53
  min: '4.10.0',
50
54
  },
@@ -5,6 +5,7 @@ import { validateParams } from '../helpers/paramsValidator';
5
5
  import { stripHexPrefix } from '../helpers/hexUtils';
6
6
 
7
7
  import type { AlephiumSignMessage as HardwareAlephiumSignMessage } from '@onekeyfe/hd-transport';
8
+ import type { DeviceFirmwareRange } from '../../types';
8
9
 
9
10
  export default class AlephiumSignMessage extends BaseMethod<HardwareAlephiumSignMessage> {
10
11
  init() {
@@ -30,8 +31,12 @@ export default class AlephiumSignMessage extends BaseMethod<HardwareAlephiumSign
30
31
  };
31
32
  }
32
33
 
33
- getVersionRange() {
34
+ getVersionRange(): DeviceFirmwareRange {
34
35
  return {
36
+ pro2: {
37
+ min: '0.0.0',
38
+ unsupported: true,
39
+ },
35
40
  model_touch: {
36
41
  min: '4.10.0',
37
42
  },
@@ -8,10 +8,11 @@ import { validateParams } from '../helpers/paramsValidator';
8
8
 
9
9
  import type {
10
10
  AlephiumSignedTx,
11
+ AlephiumTxRequest,
11
12
  AlephiumSignTx as HardwareAlephiumSignTx,
12
13
  TypedCall,
13
14
  } from '@onekeyfe/hd-transport';
14
- import type { AlephiumSignTransactionParams } from '../../types';
15
+ import type { AlephiumSignTransactionParams, DeviceFirmwareRange } from '../../types';
15
16
  import type { TypedResponseMessage } from '../../device/DeviceCommands';
16
17
 
17
18
  export default class AlephiumSignTransaction extends BaseMethod<HardwareAlephiumSignTx> {
@@ -39,8 +40,12 @@ export default class AlephiumSignTransaction extends BaseMethod<HardwareAlephium
39
40
  };
40
41
  }
41
42
 
42
- getVersionRange() {
43
+ getVersionRange(): DeviceFirmwareRange {
43
44
  return {
45
+ pro2: {
46
+ min: '0.0.0',
47
+ unsupported: true,
48
+ },
44
49
  model_touch: {
45
50
  min: '4.10.0',
46
51
  },
@@ -58,7 +63,10 @@ export default class AlephiumSignTransaction extends BaseMethod<HardwareAlephium
58
63
  data: Buffer,
59
64
  scriptOpt?: Buffer,
60
65
  dataOffset = 0
61
- ): Promise<AlephiumSignedTx> => {
66
+ // 设备可能在最后一个 AlephiumTxRequest(无 data_length)里返回签名,
67
+ // 该消息没有 address 字段,返回类型如实声明为联合类型
68
+ ): Promise<AlephiumSignedTx | AlephiumTxRequest> => {
69
+ const responseType = res.type;
62
70
  if (res.type === 'AlephiumSignedTx') {
63
71
  return res.message;
64
72
  }
@@ -109,7 +117,10 @@ export default class AlephiumSignTransaction extends BaseMethod<HardwareAlephium
109
117
  return this.processTxRequest(typedCall, response, data, scriptOpt, dataOffset);
110
118
  }
111
119
 
112
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, `Unknown response type: ${res.type}`);
120
+ throw ERRORS.TypedError(
121
+ HardwareErrorCode.RuntimeError,
122
+ `Unknown response type: ${responseType}`
123
+ );
113
124
  };
114
125
 
115
126
  async run() {
@@ -12,7 +12,7 @@ import { validateParams } from '../helpers/paramsValidator';
12
12
  import { PROTO } from '../../constants';
13
13
  import { findMethod } from '../utils';
14
14
  import { DEVICE, IFRAME, createUiMessage } from '../../events';
15
- import { getDeviceFirmwareVersion, getFirmwareType, getMethodVersionRange } from '../../utils';
15
+ import { isMethodVersionRangeUnsupported } from '../../utils';
16
16
  import { UI_REQUEST } from '../../constants/ui-request';
17
17
  import { onDeviceButtonHandler } from '../../core';
18
18
  import {
@@ -463,11 +463,12 @@ export default abstract class AllNetworkGetAddressBase extends BaseMethod<
463
463
  * @param method BaseMethod
464
464
  */
465
465
  function preCheckDeviceSupport(device: Device, method: BaseMethod) {
466
- const versionRange = getMethodVersionRange(
467
- device.features,
468
- type => method.getVersionRange()[type]
469
- );
470
- const currentVersion = getDeviceFirmwareVersion(device.features).join('.');
466
+ const versionRange = device.getCurrentMethodVersionRange(type => method.getVersionRange()[type]);
467
+ const currentVersion = device.getCurrentFirmwareVersionString() ?? '0.0.0';
468
+
469
+ if (isMethodVersionRangeUnsupported(versionRange)) {
470
+ throw ERRORS.createDeviceNotSupportMethodError(method.name, device.getCurrentFirmwareType());
471
+ }
471
472
 
472
473
  if (
473
474
  versionRange &&
@@ -478,10 +479,10 @@ function preCheckDeviceSupport(device: Device, method: BaseMethod) {
478
479
  currentVersion,
479
480
  requireVersion: versionRange.min,
480
481
  methodName: method.name,
481
- firmwareType: getFirmwareType(device.features),
482
+ firmwareType: device.getCurrentFirmwareType(),
482
483
  });
483
484
  } else if (method.strictCheckDeviceSupport && !versionRange) {
484
- throw ERRORS.createDeviceNotSupportMethodError(method.name, getFirmwareType(device.features));
485
+ throw ERRORS.createDeviceNotSupportMethodError(method.name, device.getCurrentFirmwareType());
485
486
  }
486
487
  }
487
488
 
@@ -503,11 +504,18 @@ function handleSkippableHardwareError(
503
504
  e.message?.includes('Failure_UnexpectedMessage') ||
504
505
  e.message?.includes('Failure_UnknownMessage')
505
506
  ) {
506
- const versionRange = getMethodVersionRange(
507
- device.features,
507
+ const versionRange = device.getCurrentMethodVersionRange(
508
508
  type => method.getVersionRange()[type]
509
509
  );
510
- const currentVersion = getDeviceFirmwareVersion(device.features).join('.');
510
+ const currentVersion = device.getCurrentFirmwareVersionString() ?? '0.0.0';
511
+
512
+ if (isMethodVersionRangeUnsupported(versionRange)) {
513
+ error = ERRORS.createDeviceNotSupportMethodError(
514
+ method.name,
515
+ device.getCurrentFirmwareType()
516
+ );
517
+ return error;
518
+ }
511
519
 
512
520
  if (
513
521
  versionRange &&
@@ -518,12 +526,12 @@ function handleSkippableHardwareError(
518
526
  currentVersion,
519
527
  requireVersion: versionRange.min,
520
528
  methodName: method.name,
521
- firmwareType: getFirmwareType(device.features),
529
+ firmwareType: device.getCurrentFirmwareType(),
522
530
  });
523
531
  } else {
524
532
  error = ERRORS.createDeviceNotSupportMethodError(
525
533
  method.name,
526
- getFirmwareType(device.features)
534
+ device.getCurrentFirmwareType()
527
535
  );
528
536
  }
529
537
  } else if (
@@ -5,9 +5,8 @@ import { UI_REQUEST } from '../../constants/ui-request';
5
5
  import { serializedPath, validatePath } from '../helpers/pathUtils';
6
6
  import { BaseMethod } from '../BaseMethod';
7
7
  import { validateParams, validateResult } from '../helpers/paramsValidator';
8
- import { supportBatchPublicKey } from '../../utils/deviceFeaturesUtils';
9
8
  import { hexToBytes } from '../helpers/hexUtils';
10
- import { batchGetPublickeys } from '../helpers/batchGetPublickeys';
9
+ import { batchGetPublickeys, supportBatchPublicKeyByDevice } from '../helpers/batchGetPublickeys';
11
10
 
12
11
  import type { AptosAddress, AptosGetAddressParams } from '../../types';
13
12
  import type { AptosGetAddress as HardwareAptosGetAddress } from '@onekeyfe/hd-transport';
@@ -66,7 +65,7 @@ export default class AptosGetAddress extends BaseMethod<HardwareAptosGetAddress[
66
65
  }
67
66
 
68
67
  async run() {
69
- const supportsBatchPublicKey = supportBatchPublicKey(this.device?.features);
68
+ const supportsBatchPublicKey = supportBatchPublicKeyByDevice(this.device);
70
69
  let responses: AptosAddress[] = [];
71
70
  if (supportsBatchPublicKey) {
72
71
  const publicKeyRes = await batchGetPublickeys(this.device, this.params, 'ed25519', 637);
@@ -3,10 +3,9 @@ import { validateParams, validateResult } from '../helpers/paramsValidator';
3
3
  import { serializedPath, validatePath } from '../helpers/pathUtils';
4
4
  import { UI_REQUEST } from '../../constants/ui-request';
5
5
  import { hex2BfcAddress, publicKeyToAddress } from './normalize';
6
- import { supportBatchPublicKey } from '../../utils/deviceFeaturesUtils';
7
- import { batchGetPublickeys } from '../helpers/batchGetPublickeys';
6
+ import { batchGetPublickeys, supportBatchPublicKeyByDevice } from '../helpers/batchGetPublickeys';
8
7
 
9
- import type { BenfenAddress, BenfenGetAddressParams } from '../../types';
8
+ import type { BenfenAddress, BenfenGetAddressParams, DeviceFirmwareRange } from '../../types';
10
9
  import type { BenfenGetAddress as HardwareBenfenGetAddress } from '@onekeyfe/hd-transport';
11
10
 
12
11
  export default class BenfenGetAddress extends BaseMethod<HardwareBenfenGetAddress[]> {
@@ -47,8 +46,12 @@ export default class BenfenGetAddress extends BaseMethod<HardwareBenfenGetAddres
47
46
  });
48
47
  }
49
48
 
50
- getVersionRange() {
49
+ getVersionRange(): DeviceFirmwareRange {
51
50
  return {
51
+ pro2: {
52
+ min: '0.0.0',
53
+ unsupported: true,
54
+ },
52
55
  pro: {
53
56
  min: '4.12.0',
54
57
  },
@@ -59,7 +62,7 @@ export default class BenfenGetAddress extends BaseMethod<HardwareBenfenGetAddres
59
62
  }
60
63
 
61
64
  async run() {
62
- const supportsBatchPublicKey = supportBatchPublicKey(this.device?.features);
65
+ const supportsBatchPublicKey = supportBatchPublicKeyByDevice(this.device);
63
66
  let responses: BenfenAddress[] = [];
64
67
 
65
68
  if (supportsBatchPublicKey) {
@@ -75,7 +78,8 @@ export default class BenfenGetAddress extends BaseMethod<HardwareBenfenGetAddres
75
78
  'BenfenAddress',
76
79
  param
77
80
  );
78
- address = addressRes.message.address;
81
+ // proto 里 BenfenAddress.address 是 optional;正常响应必然携带
82
+ address = addressRes.message.address ?? '';
79
83
  } else {
80
84
  address = publicKeyToAddress(publicKey);
81
85
  }
@@ -103,7 +107,7 @@ export default class BenfenGetAddress extends BaseMethod<HardwareBenfenGetAddres
103
107
  );
104
108
  const result = {
105
109
  path: serializedPath(param.address_n),
106
- address: hex2BfcAddress(res.message.address),
110
+ address: hex2BfcAddress(res.message.address ?? ''),
107
111
  };
108
112
  if (this.shouldConfirm) {
109
113
  this.postPreviousAddressMessage(result);