@onekeyfe/hd-core 1.2.0-alpha.23 → 1.2.0-alpha.25

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 (445) hide show
  1. package/__tests__/AllNetworkGetAddressBase.tracing.test.ts +2 -0
  2. package/__tests__/DeviceCommands.test.ts +35 -0
  3. package/__tests__/chain-params-onekey-compatibility.test.ts +229 -0
  4. package/__tests__/device-lifecycle-events.test.ts +59 -0
  5. package/__tests__/device-state-events.test.ts +124 -0
  6. package/__tests__/evmLedgerLegacySafety.test.ts +3 -1
  7. package/__tests__/firmware-update/check-all-firmware-release.test.ts +68 -27
  8. package/__tests__/firmware-update/firmware-update-plan.test.ts +28 -0
  9. package/__tests__/kaspa-public-types.type-test.ts +16 -0
  10. package/__tests__/kaspaSignTransaction.test.ts +4 -3
  11. package/__tests__/method-protocol-support.test.ts +113 -0
  12. package/__tests__/open-wallet-session.test.ts +192 -129
  13. package/__tests__/protocol-v2-ping.test.ts +28 -0
  14. package/__tests__/protocol-v2.test.ts +346 -230
  15. package/__tests__/public-device-state-api.test.ts +10 -8
  16. package/__tests__/public-pro2-api-boundary.test.ts +22 -0
  17. package/__tests__/tron-sign-message-init.test.ts +46 -0
  18. package/dist/api/BaseMethod.d.ts +6 -2
  19. package/dist/api/BaseMethod.d.ts.map +1 -1
  20. package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
  21. package/dist/api/CipherKeyValue.d.ts +1 -0
  22. package/dist/api/CipherKeyValue.d.ts.map +1 -1
  23. package/dist/api/DirList.d.ts +1 -0
  24. package/dist/api/DirList.d.ts.map +1 -1
  25. package/dist/api/DirMake.d.ts +1 -0
  26. package/dist/api/DirMake.d.ts.map +1 -1
  27. package/dist/api/DirRemove.d.ts +1 -0
  28. package/dist/api/DirRemove.d.ts.map +1 -1
  29. package/dist/api/FileDelete.d.ts +1 -0
  30. package/dist/api/FileDelete.d.ts.map +1 -1
  31. package/dist/api/FileRead.d.ts +1 -0
  32. package/dist/api/FileRead.d.ts.map +1 -1
  33. package/dist/api/FileWrite.d.ts +1 -0
  34. package/dist/api/FileWrite.d.ts.map +1 -1
  35. package/dist/api/FirmwareUpdate.d.ts.map +1 -1
  36. package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
  37. package/dist/api/FirmwareUpdateV4.d.ts +2 -0
  38. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  39. package/dist/api/GetDeviceState.d.ts +1 -0
  40. package/dist/api/GetDeviceState.d.ts.map +1 -1
  41. package/dist/api/GetFeatures.d.ts.map +1 -1
  42. package/dist/api/GetOnekeyFeatures.d.ts.map +1 -1
  43. package/dist/api/GetPassphraseState.d.ts +1 -0
  44. package/dist/api/GetPassphraseState.d.ts.map +1 -1
  45. package/dist/api/OpenWalletSession.d.ts +2 -8
  46. package/dist/api/OpenWalletSession.d.ts.map +1 -1
  47. package/dist/api/PathInfo.d.ts +1 -0
  48. package/dist/api/PathInfo.d.ts.map +1 -1
  49. package/dist/api/alephium/AlephiumGetAddress.d.ts.map +1 -1
  50. package/dist/api/alephium/AlephiumSignMessage.d.ts.map +1 -1
  51. package/dist/api/alephium/AlephiumSignTransaction.d.ts.map +1 -1
  52. package/dist/api/algo/AlgoGetAddress.d.ts +1 -0
  53. package/dist/api/algo/AlgoGetAddress.d.ts.map +1 -1
  54. package/dist/api/algo/AlgoSignTransaction.d.ts +1 -0
  55. package/dist/api/algo/AlgoSignTransaction.d.ts.map +1 -1
  56. package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts +1 -0
  57. package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
  58. package/dist/api/aptos/AptosGetAddress.d.ts +1 -0
  59. package/dist/api/aptos/AptosGetAddress.d.ts.map +1 -1
  60. package/dist/api/aptos/AptosGetPublicKey.d.ts +1 -0
  61. package/dist/api/aptos/AptosGetPublicKey.d.ts.map +1 -1
  62. package/dist/api/aptos/AptosSignInMessage.d.ts +1 -0
  63. package/dist/api/aptos/AptosSignInMessage.d.ts.map +1 -1
  64. package/dist/api/aptos/AptosSignMessage.d.ts +1 -0
  65. package/dist/api/aptos/AptosSignMessage.d.ts.map +1 -1
  66. package/dist/api/aptos/AptosSignTransaction.d.ts +1 -0
  67. package/dist/api/aptos/AptosSignTransaction.d.ts.map +1 -1
  68. package/dist/api/benfen/BenfenGetAddress.d.ts.map +1 -1
  69. package/dist/api/benfen/BenfenGetPublicKey.d.ts.map +1 -1
  70. package/dist/api/benfen/BenfenSignMessage.d.ts.map +1 -1
  71. package/dist/api/benfen/BenfenSignTransaction.d.ts.map +1 -1
  72. package/dist/api/btc/BTCGetAddress.d.ts +1 -0
  73. package/dist/api/btc/BTCGetAddress.d.ts.map +1 -1
  74. package/dist/api/btc/BTCGetPublicKey.d.ts +1 -0
  75. package/dist/api/btc/BTCGetPublicKey.d.ts.map +1 -1
  76. package/dist/api/btc/BTCSignMessage.d.ts +1 -0
  77. package/dist/api/btc/BTCSignMessage.d.ts.map +1 -1
  78. package/dist/api/btc/BTCSignPsbt.d.ts +1 -0
  79. package/dist/api/btc/BTCSignPsbt.d.ts.map +1 -1
  80. package/dist/api/btc/BTCSignTransaction.d.ts +1 -0
  81. package/dist/api/btc/BTCSignTransaction.d.ts.map +1 -1
  82. package/dist/api/btc/BTCVerifyMessage.d.ts +1 -0
  83. package/dist/api/btc/BTCVerifyMessage.d.ts.map +1 -1
  84. package/dist/api/btc/helpers/versionLimit.d.ts +2 -0
  85. package/dist/api/btc/helpers/versionLimit.d.ts.map +1 -1
  86. package/dist/api/cardano/CardanoGetAddress.d.ts +1 -0
  87. package/dist/api/cardano/CardanoGetAddress.d.ts.map +1 -1
  88. package/dist/api/cardano/CardanoGetPublicKey.d.ts +1 -0
  89. package/dist/api/cardano/CardanoGetPublicKey.d.ts.map +1 -1
  90. package/dist/api/cardano/CardanoSignMessage.d.ts +1 -0
  91. package/dist/api/cardano/CardanoSignMessage.d.ts.map +1 -1
  92. package/dist/api/cardano/CardanoSignTransaction.d.ts +1 -0
  93. package/dist/api/cardano/CardanoSignTransaction.d.ts.map +1 -1
  94. package/dist/api/conflux/ConfluxGetAddress.d.ts +1 -0
  95. package/dist/api/conflux/ConfluxGetAddress.d.ts.map +1 -1
  96. package/dist/api/conflux/ConfluxSignMessage.d.ts +1 -0
  97. package/dist/api/conflux/ConfluxSignMessage.d.ts.map +1 -1
  98. package/dist/api/conflux/ConfluxSignMessageCIP23.d.ts +1 -0
  99. package/dist/api/conflux/ConfluxSignMessageCIP23.d.ts.map +1 -1
  100. package/dist/api/conflux/ConfluxSignTransaction.d.ts +1 -0
  101. package/dist/api/conflux/ConfluxSignTransaction.d.ts.map +1 -1
  102. package/dist/api/cosmos/CosmosGetAddress.d.ts +1 -0
  103. package/dist/api/cosmos/CosmosGetAddress.d.ts.map +1 -1
  104. package/dist/api/cosmos/CosmosGetPublicKey.d.ts +1 -0
  105. package/dist/api/cosmos/CosmosGetPublicKey.d.ts.map +1 -1
  106. package/dist/api/cosmos/CosmosSignTransaction.d.ts +1 -0
  107. package/dist/api/cosmos/CosmosSignTransaction.d.ts.map +1 -1
  108. package/dist/api/device/DeviceCancel.d.ts +1 -0
  109. package/dist/api/device/DeviceCancel.d.ts.map +1 -1
  110. package/dist/api/device/DeviceChangePin.d.ts +1 -0
  111. package/dist/api/device/DeviceChangePin.d.ts.map +1 -1
  112. package/dist/api/device/DeviceLock.d.ts +1 -0
  113. package/dist/api/device/DeviceLock.d.ts.map +1 -1
  114. package/dist/api/device/DeviceRebootToBoardloader.d.ts +1 -0
  115. package/dist/api/device/DeviceRebootToBoardloader.d.ts.map +1 -1
  116. package/dist/api/device/DeviceRebootToBootloader.d.ts +1 -0
  117. package/dist/api/device/DeviceRebootToBootloader.d.ts.map +1 -1
  118. package/dist/api/device/DeviceSettings.d.ts +1 -0
  119. package/dist/api/device/DeviceSettings.d.ts.map +1 -1
  120. package/dist/api/device/DeviceSupportFeatures.d.ts +1 -0
  121. package/dist/api/device/DeviceSupportFeatures.d.ts.map +1 -1
  122. package/dist/api/device/DeviceUnlock.d.ts +1 -0
  123. package/dist/api/device/DeviceUnlock.d.ts.map +1 -1
  124. package/dist/api/device/DeviceWipe.d.ts +1 -0
  125. package/dist/api/device/DeviceWipe.d.ts.map +1 -1
  126. package/dist/api/device/PreInitialize.d.ts +1 -0
  127. package/dist/api/device/PreInitialize.d.ts.map +1 -1
  128. package/dist/api/dynex/DnxGetAddress.d.ts.map +1 -1
  129. package/dist/api/dynex/DnxSignTransaction.d.ts.map +1 -1
  130. package/dist/api/evm/EVMGetAddress.d.ts +1 -0
  131. package/dist/api/evm/EVMGetAddress.d.ts.map +1 -1
  132. package/dist/api/evm/EVMGetPublicKey.d.ts +1 -0
  133. package/dist/api/evm/EVMGetPublicKey.d.ts.map +1 -1
  134. package/dist/api/evm/EVMSignMessage.d.ts +1 -0
  135. package/dist/api/evm/EVMSignMessage.d.ts.map +1 -1
  136. package/dist/api/evm/EVMSignMessageEIP712.d.ts.map +1 -1
  137. package/dist/api/evm/EVMSignTransaction.d.ts +1 -0
  138. package/dist/api/evm/EVMSignTransaction.d.ts.map +1 -1
  139. package/dist/api/evm/EVMSignTypedData.d.ts +1 -0
  140. package/dist/api/evm/EVMSignTypedData.d.ts.map +1 -1
  141. package/dist/api/evm/EVMVerifyMessage.d.ts +1 -0
  142. package/dist/api/evm/EVMVerifyMessage.d.ts.map +1 -1
  143. package/dist/api/filecoin/FilecoinGetAddress.d.ts +1 -0
  144. package/dist/api/filecoin/FilecoinGetAddress.d.ts.map +1 -1
  145. package/dist/api/filecoin/FilecoinSignTransaction.d.ts +1 -0
  146. package/dist/api/filecoin/FilecoinSignTransaction.d.ts.map +1 -1
  147. package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +1 -1
  148. package/dist/api/index.d.ts +1 -0
  149. package/dist/api/index.d.ts.map +1 -1
  150. package/dist/api/kaspa/KaspaGetAddress.d.ts +1 -0
  151. package/dist/api/kaspa/KaspaGetAddress.d.ts.map +1 -1
  152. package/dist/api/kaspa/KaspaSignTransaction.d.ts +1 -0
  153. package/dist/api/kaspa/KaspaSignTransaction.d.ts.map +1 -1
  154. package/dist/api/kaspa/helpers/TransferSerialize.d.ts.map +1 -1
  155. package/dist/api/lightning/LnurlAuth.d.ts +0 -4
  156. package/dist/api/lightning/LnurlAuth.d.ts.map +1 -1
  157. package/dist/api/near/NearGetAddress.d.ts +1 -0
  158. package/dist/api/near/NearGetAddress.d.ts.map +1 -1
  159. package/dist/api/near/NearSignTransaction.d.ts +1 -0
  160. package/dist/api/near/NearSignTransaction.d.ts.map +1 -1
  161. package/dist/api/nem/NEMGetAddress.d.ts +1 -0
  162. package/dist/api/nem/NEMGetAddress.d.ts.map +1 -1
  163. package/dist/api/nem/NEMSignTransaction.d.ts +1 -0
  164. package/dist/api/nem/NEMSignTransaction.d.ts.map +1 -1
  165. package/dist/api/neo/NeoGetAddress.d.ts.map +1 -1
  166. package/dist/api/neo/NeoSignTransaction.d.ts.map +1 -1
  167. package/dist/api/nervos/NervosGetAddress.d.ts.map +1 -1
  168. package/dist/api/nervos/NervosSignTransaction.d.ts.map +1 -1
  169. package/dist/api/nexa/NexaGetAddress.d.ts.map +1 -1
  170. package/dist/api/nexa/NexaSignTransaction.d.ts.map +1 -1
  171. package/dist/api/nostr/NostrDecryptMessage.d.ts +1 -0
  172. package/dist/api/nostr/NostrDecryptMessage.d.ts.map +1 -1
  173. package/dist/api/nostr/NostrEncryptMessage.d.ts +1 -0
  174. package/dist/api/nostr/NostrEncryptMessage.d.ts.map +1 -1
  175. package/dist/api/nostr/NostrGetPublicKey.d.ts +1 -0
  176. package/dist/api/nostr/NostrGetPublicKey.d.ts.map +1 -1
  177. package/dist/api/nostr/NostrSignEvent.d.ts +1 -0
  178. package/dist/api/nostr/NostrSignEvent.d.ts.map +1 -1
  179. package/dist/api/nostr/NostrSignSchnorr.d.ts +1 -0
  180. package/dist/api/nostr/NostrSignSchnorr.d.ts.map +1 -1
  181. package/dist/api/polkadot/PolkadotGetAddress.d.ts +1 -0
  182. package/dist/api/polkadot/PolkadotGetAddress.d.ts.map +1 -1
  183. package/dist/api/polkadot/PolkadotSignTransaction.d.ts +1 -0
  184. package/dist/api/polkadot/PolkadotSignTransaction.d.ts.map +1 -1
  185. package/dist/api/protocol-v2/DeviceFactoryInfoGet.d.ts +1 -0
  186. package/dist/api/protocol-v2/DeviceFactoryInfoGet.d.ts.map +1 -1
  187. package/dist/api/protocol-v2/DeviceFactoryInfoSet.d.ts +1 -0
  188. package/dist/api/protocol-v2/DeviceFactoryInfoSet.d.ts.map +1 -1
  189. package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts +1 -0
  190. package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts.map +1 -1
  191. package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts +1 -0
  192. package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts.map +1 -1
  193. package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts +1 -0
  194. package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts.map +1 -1
  195. package/dist/api/protocol-v2/DeviceInfoGet.d.ts +1 -0
  196. package/dist/api/protocol-v2/DeviceInfoGet.d.ts.map +1 -1
  197. package/dist/api/protocol-v2/DeviceReboot.d.ts +1 -0
  198. package/dist/api/protocol-v2/DeviceReboot.d.ts.map +1 -1
  199. package/dist/api/protocol-v2/DeviceStatusGet.d.ts +1 -0
  200. package/dist/api/protocol-v2/DeviceStatusGet.d.ts.map +1 -1
  201. package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts +1 -0
  202. package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts.map +1 -1
  203. package/dist/api/protocol-v2/FilesystemFormat.d.ts +1 -0
  204. package/dist/api/protocol-v2/FilesystemFormat.d.ts.map +1 -1
  205. package/dist/api/protocol-v2/FilesystemPermissionFix.d.ts +1 -0
  206. package/dist/api/protocol-v2/FilesystemPermissionFix.d.ts.map +1 -1
  207. package/dist/api/protocol-v2/Ping.d.ts +3 -0
  208. package/dist/api/protocol-v2/Ping.d.ts.map +1 -1
  209. package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts +1 -0
  210. package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts.map +1 -1
  211. package/dist/api/scdo/ScdoGetAddress.d.ts.map +1 -1
  212. package/dist/api/scdo/ScdoSignMessage.d.ts.map +1 -1
  213. package/dist/api/scdo/ScdoSignTransaction.d.ts.map +1 -1
  214. package/dist/api/solana/SolGetAddress.d.ts +1 -0
  215. package/dist/api/solana/SolGetAddress.d.ts.map +1 -1
  216. package/dist/api/solana/SolSignMessage.d.ts +1 -0
  217. package/dist/api/solana/SolSignMessage.d.ts.map +1 -1
  218. package/dist/api/solana/SolSignOffchainMessage.d.ts +1 -0
  219. package/dist/api/solana/SolSignOffchainMessage.d.ts.map +1 -1
  220. package/dist/api/solana/SolSignTransaction.d.ts +1 -0
  221. package/dist/api/solana/SolSignTransaction.d.ts.map +1 -1
  222. package/dist/api/starcoin/StarcoinGetAddress.d.ts +1 -0
  223. package/dist/api/starcoin/StarcoinGetAddress.d.ts.map +1 -1
  224. package/dist/api/starcoin/StarcoinGetPublicKey.d.ts +1 -0
  225. package/dist/api/starcoin/StarcoinGetPublicKey.d.ts.map +1 -1
  226. package/dist/api/starcoin/StarcoinSignMessage.d.ts +1 -0
  227. package/dist/api/starcoin/StarcoinSignMessage.d.ts.map +1 -1
  228. package/dist/api/starcoin/StarcoinSignTransaction.d.ts +1 -0
  229. package/dist/api/starcoin/StarcoinSignTransaction.d.ts.map +1 -1
  230. package/dist/api/starcoin/StarcoinVerifyMessage.d.ts +1 -0
  231. package/dist/api/starcoin/StarcoinVerifyMessage.d.ts.map +1 -1
  232. package/dist/api/stellar/StellarGetAddress.d.ts +1 -2
  233. package/dist/api/stellar/StellarGetAddress.d.ts.map +1 -1
  234. package/dist/api/stellar/StellarSignTransaction.d.ts +1 -2
  235. package/dist/api/stellar/StellarSignTransaction.d.ts.map +1 -1
  236. package/dist/api/sui/SuiGetAddress.d.ts +1 -0
  237. package/dist/api/sui/SuiGetAddress.d.ts.map +1 -1
  238. package/dist/api/sui/SuiGetPublicKey.d.ts +1 -0
  239. package/dist/api/sui/SuiGetPublicKey.d.ts.map +1 -1
  240. package/dist/api/sui/SuiSignMessage.d.ts +1 -0
  241. package/dist/api/sui/SuiSignMessage.d.ts.map +1 -1
  242. package/dist/api/sui/SuiSignTransaction.d.ts +1 -0
  243. package/dist/api/sui/SuiSignTransaction.d.ts.map +1 -1
  244. package/dist/api/ton/TonGetAddress.d.ts +1 -0
  245. package/dist/api/ton/TonGetAddress.d.ts.map +1 -1
  246. package/dist/api/ton/TonSignData.d.ts +1 -0
  247. package/dist/api/ton/TonSignData.d.ts.map +1 -1
  248. package/dist/api/ton/TonSignMessage.d.ts +1 -0
  249. package/dist/api/ton/TonSignMessage.d.ts.map +1 -1
  250. package/dist/api/ton/TonSignProof.d.ts +1 -0
  251. package/dist/api/ton/TonSignProof.d.ts.map +1 -1
  252. package/dist/api/tron/TronGetAddress.d.ts +1 -0
  253. package/dist/api/tron/TronGetAddress.d.ts.map +1 -1
  254. package/dist/api/tron/TronSignMessage.d.ts +2 -0
  255. package/dist/api/tron/TronSignMessage.d.ts.map +1 -1
  256. package/dist/api/tron/TronSignTransaction.d.ts +1 -0
  257. package/dist/api/tron/TronSignTransaction.d.ts.map +1 -1
  258. package/dist/api/xrp/XrpGetAddress.d.ts +1 -0
  259. package/dist/api/xrp/XrpGetAddress.d.ts.map +1 -1
  260. package/dist/api/xrp/XrpSignTransaction.d.ts +1 -0
  261. package/dist/api/xrp/XrpSignTransaction.d.ts.map +1 -1
  262. package/dist/core/index.d.ts.map +1 -1
  263. package/dist/device/Device.d.ts +3 -1
  264. package/dist/device/Device.d.ts.map +1 -1
  265. package/dist/device/DeviceCommands.d.ts.map +1 -1
  266. package/dist/index.d.ts +25 -25
  267. package/dist/index.js +669 -367
  268. package/dist/inject.d.ts.map +1 -1
  269. package/dist/protocols/protocol-v2/unlockRetry.d.ts +2 -3
  270. package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +1 -1
  271. package/dist/protocols/protocol-v2/walletSession.d.ts +12 -0
  272. package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
  273. package/dist/types/api/export.d.ts +1 -1
  274. package/dist/types/api/export.d.ts.map +1 -1
  275. package/dist/types/api/index.d.ts +3 -1
  276. package/dist/types/api/index.d.ts.map +1 -1
  277. package/dist/types/api/kaspaSignTransaction.d.ts +15 -2
  278. package/dist/types/api/kaspaSignTransaction.d.ts.map +1 -1
  279. package/dist/types/api/openWalletSession.d.ts +0 -12
  280. package/dist/types/api/openWalletSession.d.ts.map +1 -1
  281. package/dist/types/api/protocolV2.d.ts +4 -0
  282. package/dist/types/api/protocolV2.d.ts.map +1 -1
  283. package/dist/types/device.d.ts +0 -1
  284. package/dist/types/device.d.ts.map +1 -1
  285. package/dist/utils/deviceInfoUtils.d.ts +0 -1
  286. package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
  287. package/dist/utils/deviceVersionUtils.d.ts +1 -0
  288. package/dist/utils/deviceVersionUtils.d.ts.map +1 -1
  289. package/dist/utils/index.d.ts +1 -1
  290. package/dist/utils/index.d.ts.map +1 -1
  291. package/dist/utils/patch.d.ts +1 -1
  292. package/dist/utils/patch.d.ts.map +1 -1
  293. package/package.json +4 -4
  294. package/src/api/BaseMethod.ts +21 -18
  295. package/src/api/CheckAllFirmwareRelease.ts +23 -3
  296. package/src/api/CipherKeyValue.ts +4 -0
  297. package/src/api/DirList.ts +4 -1
  298. package/src/api/DirMake.ts +4 -1
  299. package/src/api/DirRemove.ts +4 -1
  300. package/src/api/FileDelete.ts +4 -1
  301. package/src/api/FileRead.ts +4 -1
  302. package/src/api/FileWrite.ts +4 -1
  303. package/src/api/FirmwareUpdate.ts +0 -8
  304. package/src/api/FirmwareUpdateV3.ts +0 -6
  305. package/src/api/FirmwareUpdateV4.ts +36 -18
  306. package/src/api/GetDeviceState.ts +4 -0
  307. package/src/api/GetFeatures.ts +1 -4
  308. package/src/api/GetOnekeyFeatures.ts +0 -5
  309. package/src/api/GetPassphraseState.ts +4 -0
  310. package/src/api/OpenWalletSession.ts +27 -86
  311. package/src/api/PathInfo.ts +4 -1
  312. package/src/api/alephium/AlephiumGetAddress.ts +0 -4
  313. package/src/api/alephium/AlephiumSignMessage.ts +0 -4
  314. package/src/api/alephium/AlephiumSignTransaction.ts +0 -4
  315. package/src/api/algo/AlgoGetAddress.ts +4 -0
  316. package/src/api/algo/AlgoSignTransaction.ts +4 -0
  317. package/src/api/allnetwork/AllNetworkGetAddressBase.ts +5 -13
  318. package/src/api/aptos/AptosGetAddress.ts +4 -0
  319. package/src/api/aptos/AptosGetPublicKey.ts +4 -0
  320. package/src/api/aptos/AptosSignInMessage.ts +4 -0
  321. package/src/api/aptos/AptosSignMessage.ts +4 -0
  322. package/src/api/aptos/AptosSignTransaction.ts +4 -0
  323. package/src/api/benfen/BenfenGetAddress.ts +11 -7
  324. package/src/api/benfen/BenfenGetPublicKey.ts +0 -4
  325. package/src/api/benfen/BenfenSignMessage.ts +0 -4
  326. package/src/api/benfen/BenfenSignTransaction.ts +0 -4
  327. package/src/api/btc/BTCGetAddress.ts +8 -1
  328. package/src/api/btc/BTCGetPublicKey.ts +8 -1
  329. package/src/api/btc/BTCSignMessage.ts +8 -1
  330. package/src/api/btc/BTCSignPsbt.ts +4 -0
  331. package/src/api/btc/BTCSignTransaction.ts +8 -1
  332. package/src/api/btc/BTCVerifyMessage.ts +8 -1
  333. package/src/api/btc/helpers/versionLimit.ts +7 -4
  334. package/src/api/cardano/CardanoGetAddress.ts +4 -0
  335. package/src/api/cardano/CardanoGetPublicKey.ts +4 -0
  336. package/src/api/cardano/CardanoSignMessage.ts +4 -0
  337. package/src/api/cardano/CardanoSignTransaction.ts +4 -0
  338. package/src/api/conflux/ConfluxGetAddress.ts +4 -0
  339. package/src/api/conflux/ConfluxSignMessage.ts +4 -0
  340. package/src/api/conflux/ConfluxSignMessageCIP23.ts +4 -0
  341. package/src/api/conflux/ConfluxSignTransaction.ts +6 -5
  342. package/src/api/cosmos/CosmosGetAddress.ts +4 -0
  343. package/src/api/cosmos/CosmosGetPublicKey.ts +4 -0
  344. package/src/api/cosmos/CosmosSignTransaction.ts +4 -0
  345. package/src/api/device/DeviceCancel.ts +4 -0
  346. package/src/api/device/DeviceChangePin.ts +4 -0
  347. package/src/api/device/DeviceLock.ts +4 -0
  348. package/src/api/device/DeviceRebootToBoardloader.ts +4 -0
  349. package/src/api/device/DeviceRebootToBootloader.ts +4 -0
  350. package/src/api/device/DeviceSettings.ts +4 -0
  351. package/src/api/device/DeviceSupportFeatures.ts +4 -0
  352. package/src/api/device/DeviceUnlock.ts +4 -0
  353. package/src/api/device/DeviceWipe.ts +4 -0
  354. package/src/api/device/PreInitialize.ts +4 -0
  355. package/src/api/dynex/DnxGetAddress.ts +0 -6
  356. package/src/api/dynex/DnxSignTransaction.ts +0 -6
  357. package/src/api/evm/EVMGetAddress.ts +4 -0
  358. package/src/api/evm/EVMGetPublicKey.ts +4 -0
  359. package/src/api/evm/EVMSignMessage.ts +4 -0
  360. package/src/api/evm/EVMSignMessageEIP712.ts +1 -11
  361. package/src/api/evm/EVMSignTransaction.ts +4 -0
  362. package/src/api/evm/EVMSignTypedData.ts +4 -0
  363. package/src/api/evm/EVMVerifyMessage.ts +4 -0
  364. package/src/api/filecoin/FilecoinGetAddress.ts +4 -0
  365. package/src/api/filecoin/FilecoinSignTransaction.ts +4 -0
  366. package/src/api/firmware/FirmwareUpdatePlan.ts +8 -1
  367. package/src/api/index.ts +1 -0
  368. package/src/api/kaspa/KaspaGetAddress.ts +4 -0
  369. package/src/api/kaspa/KaspaSignTransaction.ts +37 -15
  370. package/src/api/kaspa/helpers/TransferSerialize.ts +3 -7
  371. package/src/api/lightning/LnurlAuth.ts +0 -4
  372. package/src/api/near/NearGetAddress.ts +4 -0
  373. package/src/api/near/NearSignTransaction.ts +4 -0
  374. package/src/api/nem/NEMGetAddress.ts +4 -0
  375. package/src/api/nem/NEMSignTransaction.ts +4 -0
  376. package/src/api/neo/NeoGetAddress.ts +0 -4
  377. package/src/api/neo/NeoSignTransaction.ts +0 -4
  378. package/src/api/nervos/NervosGetAddress.ts +0 -4
  379. package/src/api/nervos/NervosSignTransaction.ts +0 -4
  380. package/src/api/nexa/NexaGetAddress.ts +0 -4
  381. package/src/api/nexa/NexaSignTransaction.ts +0 -4
  382. package/src/api/nostr/NostrDecryptMessage.ts +4 -0
  383. package/src/api/nostr/NostrEncryptMessage.ts +4 -0
  384. package/src/api/nostr/NostrGetPublicKey.ts +4 -0
  385. package/src/api/nostr/NostrSignEvent.ts +4 -0
  386. package/src/api/nostr/NostrSignSchnorr.ts +4 -0
  387. package/src/api/polkadot/PolkadotGetAddress.ts +4 -0
  388. package/src/api/polkadot/PolkadotSignTransaction.ts +4 -0
  389. package/src/api/protocol-v2/DeviceFactoryInfoGet.ts +4 -1
  390. package/src/api/protocol-v2/DeviceFactoryInfoSet.ts +4 -1
  391. package/src/api/protocol-v2/DeviceFirmwareUpdate.ts +4 -1
  392. package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +4 -1
  393. package/src/api/protocol-v2/DeviceGetOnboardingStatus.ts +4 -1
  394. package/src/api/protocol-v2/DeviceInfoGet.ts +4 -8
  395. package/src/api/protocol-v2/DeviceReboot.ts +4 -2
  396. package/src/api/protocol-v2/DeviceStatusGet.ts +4 -1
  397. package/src/api/protocol-v2/DeviceUploadWallpaper.ts +4 -1
  398. package/src/api/protocol-v2/FilesystemFormat.ts +4 -1
  399. package/src/api/protocol-v2/FilesystemPermissionFix.ts +4 -1
  400. package/src/api/protocol-v2/Ping.ts +36 -2
  401. package/src/api/protocol-v2/ProtocolInfoRequest.ts +4 -1
  402. package/src/api/scdo/ScdoGetAddress.ts +0 -4
  403. package/src/api/scdo/ScdoSignMessage.ts +0 -4
  404. package/src/api/scdo/ScdoSignTransaction.ts +0 -4
  405. package/src/api/solana/SolGetAddress.ts +4 -0
  406. package/src/api/solana/SolSignMessage.ts +4 -0
  407. package/src/api/solana/SolSignOffchainMessage.ts +4 -0
  408. package/src/api/solana/SolSignTransaction.ts +4 -0
  409. package/src/api/starcoin/StarcoinGetAddress.ts +4 -0
  410. package/src/api/starcoin/StarcoinGetPublicKey.ts +4 -0
  411. package/src/api/starcoin/StarcoinSignMessage.ts +4 -0
  412. package/src/api/starcoin/StarcoinSignTransaction.ts +4 -0
  413. package/src/api/starcoin/StarcoinVerifyMessage.ts +4 -0
  414. package/src/api/stellar/StellarGetAddress.ts +1 -10
  415. package/src/api/stellar/StellarSignTransaction.ts +1 -14
  416. package/src/api/sui/SuiGetAddress.ts +4 -0
  417. package/src/api/sui/SuiGetPublicKey.ts +4 -0
  418. package/src/api/sui/SuiSignMessage.ts +4 -0
  419. package/src/api/sui/SuiSignTransaction.ts +4 -0
  420. package/src/api/ton/TonGetAddress.ts +4 -0
  421. package/src/api/ton/TonSignData.ts +5 -1
  422. package/src/api/ton/TonSignMessage.ts +4 -0
  423. package/src/api/ton/TonSignProof.ts +4 -0
  424. package/src/api/tron/TronGetAddress.ts +4 -0
  425. package/src/api/tron/TronSignMessage.ts +15 -7
  426. package/src/api/tron/TronSignTransaction.ts +4 -0
  427. package/src/api/xrp/XrpGetAddress.ts +4 -0
  428. package/src/api/xrp/XrpSignTransaction.ts +5 -1
  429. package/src/core/index.ts +43 -24
  430. package/src/data/messages/messages-protocol-v2.json +33 -1
  431. package/src/device/Device.ts +60 -62
  432. package/src/device/DeviceCommands.ts +19 -0
  433. package/src/inject.ts +2 -0
  434. package/src/protocols/protocol-v2/unlockRetry.ts +20 -3
  435. package/src/protocols/protocol-v2/walletSession.ts +26 -8
  436. package/src/types/api/export.ts +2 -0
  437. package/src/types/api/index.ts +3 -0
  438. package/src/types/api/kaspaSignTransaction.ts +20 -2
  439. package/src/types/api/openWalletSession.ts +0 -19
  440. package/src/types/api/protocolV2.ts +10 -0
  441. package/src/types/device.ts +0 -1
  442. package/src/utils/deviceInfoUtils.ts +15 -6
  443. package/src/utils/deviceVersionUtils.ts +1 -1
  444. package/src/utils/index.ts +0 -1
  445. package/tsconfig.type-tests.json +8 -0
@@ -25,6 +25,7 @@ describe('AllNetworkGetAddressBase tracing', () => {
25
25
  connectId: 'connect-id',
26
26
  deviceId: 'device-id',
27
27
  getVersionRange: jest.fn().mockReturnValue({}),
28
+ assertProtocolSupported: jest.fn(),
28
29
  init: jest.fn(),
29
30
  name: 'xrpGetAddress',
30
31
  responseID: 42,
@@ -45,6 +46,7 @@ describe('AllNetworkGetAddressBase tracing', () => {
45
46
  method.device = {
46
47
  instanceId: deviceInstanceId,
47
48
  getCurrentFirmwareType: jest.fn(),
49
+ getProtocol: jest.fn().mockReturnValue('V1'),
48
50
  getCurrentFirmwareVersionString: jest.fn().mockReturnValue('1.0.0'),
49
51
  getCurrentMethodVersionRange: jest
50
52
  .fn()
@@ -103,6 +103,41 @@ describe('DeviceCommands failure mapping', () => {
103
103
  ).rejects.toMatchObject({ errorCode: code });
104
104
  });
105
105
 
106
+ it.each([
107
+ ['DeviceSessionGet', 5, 'Another flow in progress'],
108
+ ['DeviceSessionAskPin', 0, 'Busy'],
109
+ ])('maps %s firmware busy failures to DeviceBusy', async (callType, subcode, message) => {
110
+ const commands = createCommands();
111
+
112
+ await expect(
113
+ commands._filterCommonTypes(
114
+ {
115
+ type: 'Failure',
116
+ message: { code: 'Failure_ProcessError', subcode, message },
117
+ } as any,
118
+ callType
119
+ )
120
+ ).rejects.toMatchObject({ errorCode: HardwareErrorCode.DeviceBusy });
121
+ });
122
+
123
+ it('maps the current AskPin passphrase-disabled response without relying on a subcode', async () => {
124
+ const commands = createCommands();
125
+
126
+ await expect(
127
+ commands._filterCommonTypes(
128
+ {
129
+ type: 'Failure',
130
+ message: {
131
+ code: 'Failure_ProcessError',
132
+ subcode: 0,
133
+ message: 'Passphrase disabled',
134
+ },
135
+ } as any,
136
+ 'DeviceSessionAskPin'
137
+ )
138
+ ).rejects.toMatchObject({ errorCode: HardwareErrorCode.DeviceNotOpenedPassphrase });
139
+ });
140
+
106
141
  it('rejects the Pro2 bootloader DeviceStatusGet unsupported response', async () => {
107
142
  const commands = createCommands();
108
143
 
@@ -0,0 +1,229 @@
1
+ import { EDeviceType, EFirmwareType } from '@onekeyfe/hd-shared';
2
+
3
+ import BenfenGetAddress from '../src/api/benfen/BenfenGetAddress';
4
+ import ConfluxSignTransaction from '../src/api/conflux/ConfluxSignTransaction';
5
+ import EVMSignTransaction from '../src/api/evm/EVMSignTransaction';
6
+ import EVMSignMessageEIP712 from '../src/api/evm/EVMSignMessageEIP712';
7
+ import KaspaSignTransaction from '../src/api/kaspa/KaspaSignTransaction';
8
+ import XrpSignTransaction from '../src/api/xrp/XrpSignTransaction';
9
+
10
+ import type { Device } from '../src/device/Device';
11
+
12
+ jest.mock('../src/data/config', () => ({
13
+ getSDKVersion: jest.fn(() => '1.0.0'),
14
+ DEFAULT_DOMAIN: 'https://jssdk.onekey.so/1.0.0/',
15
+ }));
16
+
17
+ jest.mock('../src/data-manager/TransportManager', () => ({
18
+ getProtocolV1MessageSchema: jest.fn(() => 'v1CurrentSchema'),
19
+ }));
20
+
21
+ jest.mock('../src/device/Device', () => ({
22
+ Device: jest.fn(),
23
+ }));
24
+
25
+ const KASPA_PATH = "m/44'/111111'/0'/0/0";
26
+ const KASPA_SCRIPT = `20${'ab'.repeat(32)}ac`;
27
+ const KASPA_ADDRESS = 'kaspa:qr0lr4ml9fn3chekrqmjdkergxl93l4wrk3dankcgvjq776s9wn9jkdskewva';
28
+
29
+ const buildKaspaPayload = () => ({
30
+ method: 'kaspaSignTransaction',
31
+ version: 0,
32
+ lockTime: 0,
33
+ inputs: [
34
+ {
35
+ path: KASPA_PATH,
36
+ prevTxId: 'aa'.repeat(32),
37
+ outputIndex: 0,
38
+ sequenceNumber: 0,
39
+ output: { satoshis: 200000, script: KASPA_SCRIPT },
40
+ },
41
+ ],
42
+ outputs: [{ satoshis: 100000, script: KASPA_SCRIPT, scriptVersion: 0 }],
43
+ });
44
+
45
+ describe('onekey public-chain parameter compatibility', () => {
46
+ it('keeps the historical EVM contract-deployment representation', () => {
47
+ const transaction = {
48
+ to: '',
49
+ value: '0x0',
50
+ gasPrice: '0x1',
51
+ gasLimit: '0x5208',
52
+ nonce: '0x0',
53
+ chainId: 1,
54
+ data: '0x6000',
55
+ };
56
+
57
+ const method = new EVMSignTransaction({
58
+ id: 1,
59
+ payload: {
60
+ method: 'evmSignTransaction',
61
+ path: "m/44'/60'/0'/0/0",
62
+ transaction,
63
+ },
64
+ });
65
+
66
+ expect(() => method.init()).not.toThrow();
67
+
68
+ const { to: _to, ...transactionWithoutTo } = transaction;
69
+ const missingTo = new EVMSignTransaction({
70
+ id: 2,
71
+ payload: {
72
+ method: 'evmSignTransaction',
73
+ path: "m/44'/60'/0'/0/0",
74
+ transaction: transactionWithoutTo,
75
+ },
76
+ });
77
+
78
+ expect(() => missingTo.init()).toThrow('Missing required parameter: to');
79
+ });
80
+
81
+ it('keeps Conflux to validation aligned with onekey', () => {
82
+ const method = new ConfluxSignTransaction({
83
+ id: 1,
84
+ payload: {
85
+ method: 'confluxSignTransaction',
86
+ path: "m/44'/503'/0'/0/0",
87
+ transaction: {
88
+ to: 'cfx:aak2rra2njvd77ezwjvx04kkds9fzagfe6d5r8e957',
89
+ value: '0x0',
90
+ gasLimit: '0x5208',
91
+ gasPrice: '0x1',
92
+ nonce: '0x0',
93
+ epochHeight: '0x1',
94
+ storageLimit: '0x0',
95
+ chainId: 1029,
96
+ },
97
+ },
98
+ });
99
+
100
+ expect(() => method.init()).toThrow('should be [hexString]');
101
+ });
102
+
103
+ it('keeps XRP payment amount as the historical number input', () => {
104
+ const createMethod = (amount: number | string) =>
105
+ new XrpSignTransaction({
106
+ id: 1,
107
+ payload: {
108
+ method: 'xrpSignTransaction',
109
+ path: "m/44'/144'/0'/0/0",
110
+ transaction: {
111
+ payment: {
112
+ amount,
113
+ destination: 'rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn',
114
+ },
115
+ },
116
+ },
117
+ });
118
+
119
+ expect(() => createMethod(1).init()).not.toThrow();
120
+ expect(() => createMethod('1').init()).toThrow('should be [number]');
121
+ });
122
+
123
+ it('keeps the Kaspa legacy schema while allowing the additive streaming shape', () => {
124
+ const legacyWithoutSigHash = new KaspaSignTransaction({
125
+ id: 1,
126
+ payload: buildKaspaPayload(),
127
+ });
128
+ expect(() => legacyWithoutSigHash.init()).toThrow('Missing required parameter: sigHashType');
129
+
130
+ const legacyWithoutScript = new KaspaSignTransaction({
131
+ id: 2,
132
+ payload: {
133
+ ...buildKaspaPayload(),
134
+ sigHashType: 0x41,
135
+ outputs: [{ satoshis: 100000, scriptVersion: 0 }],
136
+ },
137
+ });
138
+ expect(() => legacyWithoutScript.init()).toThrow('Missing required parameter: script');
139
+
140
+ const streaming = new KaspaSignTransaction({
141
+ id: 3,
142
+ payload: {
143
+ ...buildKaspaPayload(),
144
+ inputs: [
145
+ {
146
+ ...buildKaspaPayload().inputs[0],
147
+ output: { satoshis: 200000 },
148
+ },
149
+ ],
150
+ outputs: [{ satoshis: 100000, address: KASPA_ADDRESS }],
151
+ },
152
+ });
153
+ expect(() => streaming.init()).not.toThrow();
154
+ });
155
+
156
+ it('keeps validating the Kaspa legacy input amount', () => {
157
+ const payload = buildKaspaPayload();
158
+ const method = new KaspaSignTransaction({
159
+ id: 1,
160
+ payload: {
161
+ ...payload,
162
+ sigHashType: 0x41,
163
+ inputs: [
164
+ {
165
+ ...payload.inputs[0],
166
+ output: { script: KASPA_SCRIPT },
167
+ },
168
+ ],
169
+ },
170
+ });
171
+
172
+ expect(() => method.init()).toThrow('Missing required parameter: satoshis');
173
+ });
174
+
175
+ it('keeps the deprecated EIP-712 method callable on existing Protocol V1 devices', async () => {
176
+ const method = new EVMSignMessageEIP712({
177
+ id: 1,
178
+ payload: {
179
+ method: 'evmSignMessageEIP712',
180
+ path: "m/44'/60'/0'/0/0",
181
+ domainHash: `0x${'11'.repeat(32)}`,
182
+ messageHash: `0x${'22'.repeat(32)}`,
183
+ },
184
+ });
185
+ method.init();
186
+
187
+ const typedCall = jest.fn().mockResolvedValue({
188
+ message: {
189
+ address: '0x1234',
190
+ signature: 'abcd',
191
+ },
192
+ });
193
+ method.device = {
194
+ commands: { typedCall },
195
+ getCurrentFirmwareVersionString: jest.fn(() => '4.10.0'),
196
+ getCurrentMethodVersionRange: jest.fn(() => undefined),
197
+ getCurrentFirmwareType: jest.fn(() => EFirmwareType.Universal),
198
+ getProtocol: jest.fn(() => 'V1'),
199
+ } as unknown as Device;
200
+
201
+ await expect(method.run()).resolves.toEqual({
202
+ address: '0x1234',
203
+ signature: 'abcd',
204
+ });
205
+ expect(typedCall).toHaveBeenCalledTimes(1);
206
+ });
207
+
208
+ it('rejects a Benfen response that omits the address', async () => {
209
+ const method = new BenfenGetAddress({
210
+ id: 1,
211
+ payload: {
212
+ method: 'benfenGetAddress',
213
+ path: "m/44'/728'/0'/0'/0'",
214
+ showOnOneKey: false,
215
+ },
216
+ });
217
+ method.init();
218
+ method.device = {
219
+ commands: {
220
+ typedCall: jest.fn().mockResolvedValue({ message: {} }),
221
+ },
222
+ getCurrentFirmwareVersionString: jest.fn(() => '1.0.0'),
223
+ getCurrentDeviceType: jest.fn(() => EDeviceType.Classic),
224
+ isProtocolV2: jest.fn(() => false),
225
+ } as unknown as Device;
226
+
227
+ await expect(method.run()).rejects.toThrow(/address/i);
228
+ });
229
+ });
@@ -1,3 +1,5 @@
1
+ import { TRANSPORT_EVENT } from '@onekeyfe/hd-transport';
2
+
1
3
  import { initConnector, initCore } from '../src/core';
2
4
  import { DataManager } from '../src/data-manager';
3
5
  import TransportManager from '../src/data-manager/TransportManager';
@@ -59,6 +61,63 @@ describe('public device lifecycle events', () => {
59
61
  jest.restoreAllMocks();
60
62
  });
61
63
 
64
+ test('registers the shared device lifecycle listeners exactly once', async () => {
65
+ jest.spyOn(DataManager, 'getSettings').mockReturnValue('react-native' as never);
66
+ core = initCore();
67
+ initConnector();
68
+
69
+ for (const id of ['first-call', 'second-call']) {
70
+ await core.handleMessage({
71
+ id,
72
+ event: IFRAME.CALL,
73
+ type: IFRAME.CALL,
74
+ payload: { method: 'clearSessionCache' },
75
+ } as CoreMessage);
76
+ }
77
+
78
+ expect(DevicePool.emitter.listenerCount(DEVICE.CONNECT)).toBe(1);
79
+ expect(DevicePool.emitter.listenerCount(DEVICE.DISCONNECT)).toBe(1);
80
+ });
81
+
82
+ test('converts an internal transport disconnect into a public KnownDevice snapshot', () => {
83
+ jest.spyOn(DataManager, 'getSettings').mockReturnValue('react-native' as never);
84
+ core = initCore();
85
+ initConnector();
86
+ const messages: CoreMessage[] = [];
87
+ core.on(CORE_EVENT, message => messages.push(message));
88
+ const device = createInitializedDevice('V2');
89
+ DevicePool.devicesCache['ble-connect-id'] = device;
90
+
91
+ DevicePool.emitter.emit(TRANSPORT_EVENT.DEVICE_DISCONNECT, {
92
+ id: 'ble-connect-id',
93
+ connectId: 'ble-connect-id',
94
+ name: 'OneKey Test BLE',
95
+ });
96
+
97
+ const disconnectMessage = messages.find(message => message.type === DEVICE.DISCONNECT);
98
+ expect(disconnectMessage?.payload.device).toMatchObject({
99
+ connectId: 'ble-connect-id',
100
+ serialNo: 'SERIAL-001',
101
+ state: { protocol: 'V2' },
102
+ });
103
+ expect(() => JSON.stringify(disconnectMessage?.payload.device)).not.toThrow();
104
+ });
105
+
106
+ test('treats an acquired BLE device as reusable until the transport disconnects', async () => {
107
+ jest.spyOn(DataManager, 'getSettings').mockReturnValue('desktop-web-ble' as never);
108
+ const device = createInitializedDevice('V2');
109
+ const acquire = jest.spyOn(device, 'acquire').mockResolvedValue(undefined);
110
+ (device as unknown as { deviceAcquired: boolean }).deviceAcquired = true;
111
+ (device as any).commands = { disposed: false };
112
+
113
+ expect(device.isUsedHere()).toBe(true);
114
+ await expect(device.connect('V2')).resolves.toBe(true);
115
+ expect(acquire).not.toHaveBeenCalled();
116
+
117
+ device.markTransportDisconnected();
118
+ expect(device.isUsedHere()).toBe(false);
119
+ });
120
+
62
121
  test.each([
63
122
  ['react-native', 'V1'],
64
123
  ['react-native', 'V2'],
@@ -1,3 +1,6 @@
1
+ import { EDeviceType, EFirmwareType } from '@onekeyfe/hd-shared';
2
+ import { Enum_SafetyCheckLevel } from '@onekeyfe/hd-transport';
3
+
1
4
  import { Device } from '../src/device/Device';
2
5
  import { DEVICE } from '../src/events';
3
6
  import { EOneKeyDeviceMode } from '../src/types';
@@ -8,6 +11,127 @@ jest.mock('../src/data/config', () => ({
8
11
  }));
9
12
 
10
13
  describe('Device state events', () => {
14
+ test.each([
15
+ ['V1', EFirmwareType.BitcoinOnly],
16
+ ['V2', EFirmwareType.Universal],
17
+ ] as const)(
18
+ 'reads the current %s firmware type from canonical state',
19
+ (protocol, firmwareType) => {
20
+ const device = Device.fromDescriptor({
21
+ id: `device-${protocol}`,
22
+ path: `device-${protocol}`,
23
+ protocolType: protocol,
24
+ } as never);
25
+ device.updateState({ protocol, identity: { firmwareType } }, 'initialize');
26
+ const featuresGetter = jest.spyOn(device, 'features', 'get').mockImplementation(() => {
27
+ throw new Error('Legacy Features projection should not be read');
28
+ });
29
+
30
+ expect(device.getCurrentFirmwareType()).toBe(firmwareType);
31
+ featuresGetter.mockRestore();
32
+ }
33
+ );
34
+
35
+ test('keeps the universal firmware fallback before device state is initialized', () => {
36
+ const device = Device.fromDescriptor({ id: 'pending', path: 'pending' } as never);
37
+
38
+ expect(device.getCurrentFirmwareType()).toBe(EFirmwareType.Universal);
39
+ expect(device.getCurrentDeviceType()).toBe(EDeviceType.Unknown);
40
+ expect(device.getCurrentDeviceId()).toBeUndefined();
41
+ expect(device.getCurrentSerialNo()).toBe('');
42
+ expect(device.getCurrentBleName()).toBeNull();
43
+ expect(device.getCurrentLabel()).toBeNull();
44
+ expect(device.getCurrentFirmwareVersionString()).toBe('0.0.0');
45
+ expect(device.getCurrentBLEFirmwareVersionString()).toBeUndefined();
46
+ expect(device.getCurrentBootloaderVersionString()).toBeUndefined();
47
+ expect(device.getFirmwareVersion()).toBeNull();
48
+ expect(device.getBLEFirmwareVersion()).toBeNull();
49
+ expect(device.isUnacquired()).toBe(true);
50
+ });
51
+
52
+ test('reads current device data from canonical state without projecting Features', () => {
53
+ const device = Device.fromDescriptor({
54
+ id: 'pro2-state',
55
+ path: 'pro2-state',
56
+ protocolType: 'V2',
57
+ } as never);
58
+ device.updateState(
59
+ {
60
+ protocol: 'V2',
61
+ identity: {
62
+ deviceType: EDeviceType.Pro2,
63
+ deviceId: 'wallet-id',
64
+ serialNo: 'SERIAL-PRO2',
65
+ label: null,
66
+ bleName: 'Pro2 1234',
67
+ },
68
+ status: {
69
+ mode: 'normal',
70
+ initialized: true,
71
+ unlocked: false,
72
+ noBackup: false,
73
+ passphraseProtection: false,
74
+ },
75
+ settings: { safetyChecks: Enum_SafetyCheckLevel.Strict },
76
+ versions: {
77
+ firmware: '5.1.2',
78
+ bootloader: '2.0.0',
79
+ ble: null,
80
+ },
81
+ },
82
+ 'initialize'
83
+ );
84
+ const featuresGetter = jest.spyOn(device, 'features', 'get').mockImplementation(() => {
85
+ throw new Error('Legacy Features projection should not be read');
86
+ });
87
+
88
+ expect(device.getCurrentDeviceType()).toBe(EDeviceType.Pro2);
89
+ expect(device.getCurrentDeviceId()).toBe('wallet-id');
90
+ expect(device.getCurrentSerialNo()).toBe('SERIAL-PRO2');
91
+ expect(device.getCurrentBleName()).toBe('Pro2 1234');
92
+ expect(device.getCurrentLabel()).toBeNull();
93
+ expect((device as any).getCurrentDisplayName()).toBe('Pro2 1234');
94
+ expect(device.getCurrentPassphraseProtection()).toBe(false);
95
+ expect(device.getCurrentFirmwareVersionString()).toBe('5.1.2');
96
+ expect(device.getCurrentBLEFirmwareVersionString()).toBe('0.0.0');
97
+ expect(device.getCurrentBootloaderVersionString()).toBe('2.0.0');
98
+ expect(device.getCurrentSafetyChecks()).toBe(Enum_SafetyCheckLevel.Strict);
99
+ expect(device.getFirmwareVersion()).toEqual([5, 1, 2]);
100
+ expect(device.getBLEFirmwareVersion()).toEqual([0, 0, 0]);
101
+ expect(device.isBootloader()).toBe(false);
102
+ expect(device.isInitialized()).toBe(true);
103
+ expect(device.isSeedless()).toBe(false);
104
+ expect(device.isUnacquired()).toBe(false);
105
+ expect(device.hasUsePassphrase()).toBe(true);
106
+ expect(device.supportInputPinOnSoftware()).toEqual({ support: false });
107
+ expect(device.supportModifyHomescreen()).toEqual({ support: true });
108
+ featuresGetter.mockRestore();
109
+ });
110
+
111
+ test('keeps legacy display-name fallbacks separate from the canonical label', () => {
112
+ const device = Device.fromDescriptor({ id: 'pure', path: 'pure' } as never);
113
+ device.updateState(
114
+ {
115
+ protocol: 'V1',
116
+ identity: {
117
+ deviceType: EDeviceType.ClassicPure,
118
+ label: null,
119
+ bleName: null,
120
+ },
121
+ status: { mode: 'normal', initialized: true },
122
+ },
123
+ 'initialize'
124
+ );
125
+
126
+ expect(device.getCurrentLabel()).toBeNull();
127
+ expect(device.getCurrentDisplayName()).toBe('OneKey Classic 1S');
128
+ expect(device.toMessageObject()).toMatchObject({
129
+ name: 'OneKey Classic 1S',
130
+ label: 'OneKey Classic 1S',
131
+ state: { identity: { label: null } },
132
+ });
133
+ });
134
+
11
135
  test('emits only the canonical state event for Protocol V2', () => {
12
136
  const device = Device.fromDescriptor({
13
137
  id: 'pro2',
@@ -1,10 +1,11 @@
1
+ import { Enum_SafetyCheckLevel } from '@onekeyfe/hd-transport';
2
+
1
3
  import AllNetworkGetAddressBase from '../src/api/allnetwork/AllNetworkGetAddressBase';
2
4
  import EvmGetAddress from '../src/api/evm/EVMGetAddress';
3
5
  import EVMGetPublicKey from '../src/api/evm/EVMGetPublicKey';
4
6
  import { findMethod } from '../src/api/utils';
5
7
  import { getDeviceType, getFirmwareType, getMethodVersionRange } from '../src/utils';
6
8
  import { getDeviceFirmwareVersion } from '../src/utils/deviceVersionUtils';
7
- import { Enum_SafetyCheckLevel } from '@onekeyfe/hd-transport';
8
9
 
9
10
  import type { EDeviceType } from '@onekeyfe/hd-shared';
10
11
 
@@ -33,6 +34,7 @@ const createDevice = (onekeyDeviceType: string) => {
33
34
  },
34
35
  // BaseMethod reads state through Device accessors; reuse production mappers in the stub.
35
36
  isProtocolV2: () => false,
37
+ getProtocol: () => 'V1' as const,
36
38
  getCurrentDeviceType: () => getDeviceType(features as any),
37
39
  getCurrentSafetyChecks: () => features.safety_checks,
38
40
  getCurrentFirmwareType: () => getFirmwareType(features as any),
@@ -1,4 +1,4 @@
1
- import { EDeviceType, EFirmwareType } from '@onekeyfe/hd-shared';
1
+ import { ERRORS, EDeviceType, EFirmwareType, HardwareErrorCode } from '@onekeyfe/hd-shared';
2
2
 
3
3
  import CheckAllFirmwareRelease from '../../src/api/CheckAllFirmwareRelease';
4
4
  import { buildFirmwareUpdatePlan } from '../../src/api/firmware/FirmwareUpdatePlan';
@@ -36,7 +36,40 @@ const mockGetFirmwareReleaseInfo = getFirmwareReleaseInfo as jest.MockedFunction
36
36
  typeof getFirmwareReleaseInfo
37
37
  >;
38
38
 
39
+ const noUpdate = {
40
+ status: 'valid' as const,
41
+ release: undefined,
42
+ };
43
+
44
+ const createMethod = (serialNo = 'device-id') => {
45
+ const method = new CheckAllFirmwareRelease({
46
+ id: 1,
47
+ payload: {
48
+ method: 'checkAllFirmwareRelease',
49
+ platform: 'native',
50
+ },
51
+ });
52
+ method.init();
53
+ method.device = {
54
+ features: {
55
+ deviceType: EDeviceType.Classic1s,
56
+ serialNo,
57
+ firmwareType: EFirmwareType.Universal,
58
+ firmwareVersion: '1.0.0',
59
+ bootloaderVersion: '1.0.0',
60
+ },
61
+ } as typeof method.device;
62
+ return method;
63
+ };
64
+
39
65
  describe('CheckAllFirmwareRelease', () => {
66
+ beforeEach(() => {
67
+ jest.clearAllMocks();
68
+ mockGetFirmwareReleaseInfo.mockReturnValue(noUpdate);
69
+ mockGetBootloaderReleaseInfo.mockReturnValue(noUpdate);
70
+ mockGetBleFirmwareReleaseInfo.mockReturnValue(noUpdate);
71
+ });
72
+
40
73
  test('keeps release information available when an optional Plan cannot be built', async () => {
41
74
  const firmware = {
42
75
  status: 'outdated' as const,
@@ -45,36 +78,14 @@ describe('CheckAllFirmwareRelease', () => {
45
78
  version: [3, 0, 0],
46
79
  },
47
80
  };
48
- const noUpdate = {
49
- status: 'valid' as const,
50
- release: undefined,
51
- };
52
81
  mockGetFirmwareReleaseInfo.mockReturnValue(firmware);
53
- mockGetBootloaderReleaseInfo.mockReturnValue(noUpdate);
54
- mockGetBleFirmwareReleaseInfo.mockReturnValue(noUpdate);
55
82
  mockBuildFirmwareUpdatePlan.mockImplementation(() => {
56
- throw new Error('FirmwarePlanInvalid');
57
- });
58
-
59
- const method = new CheckAllFirmwareRelease({
60
- id: 1,
61
- payload: {
62
- method: 'checkAllFirmwareRelease',
63
- platform: 'native',
64
- },
83
+ throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Plan cannot be built', {
84
+ firmwareUpdateCode: 'FirmwarePlanInvalid',
85
+ });
65
86
  });
66
- method.init();
67
- method.device = {
68
- features: {
69
- deviceType: EDeviceType.Classic1s,
70
- serialNo: '',
71
- firmwareType: EFirmwareType.Universal,
72
- firmwareVersion: '1.0.0',
73
- bootloaderVersion: '1.0.0',
74
- },
75
- } as typeof method.device;
76
87
 
77
- await expect(method.run()).resolves.toEqual(
88
+ await expect(createMethod('').run()).resolves.toEqual(
78
89
  expect.objectContaining({
79
90
  firmware,
80
91
  bootloader: noUpdate,
@@ -83,4 +94,34 @@ describe('CheckAllFirmwareRelease', () => {
83
94
  })
84
95
  );
85
96
  });
97
+
98
+ test('returns an optional Plan when the builder succeeds', async () => {
99
+ const plan = {
100
+ schemaVersion: 2 as const,
101
+ planDigest: 'a'.repeat(64),
102
+ executor: 'v3' as const,
103
+ deviceIdentity: 'device-id',
104
+ deviceModel: EDeviceType.Classic1s,
105
+ firmwareType: EFirmwareType.Universal,
106
+ platform: 'native' as const,
107
+ artifacts: [],
108
+ targetsToUpdate: [],
109
+ };
110
+ mockBuildFirmwareUpdatePlan.mockReturnValue(plan);
111
+
112
+ await expect(createMethod().run()).resolves.toEqual(
113
+ expect.objectContaining({
114
+ firmwareUpdatePlan: plan,
115
+ })
116
+ );
117
+ });
118
+
119
+ test('does not hide unexpected Plan builder failures', async () => {
120
+ const unexpectedError = new Error('unexpected builder failure');
121
+ mockBuildFirmwareUpdatePlan.mockImplementation(() => {
122
+ throw unexpectedError;
123
+ });
124
+
125
+ await expect(createMethod().run()).rejects.toBe(unexpectedError);
126
+ });
86
127
  });
@@ -293,6 +293,34 @@ describe('buildFirmwareUpdatePlan', () => {
293
293
  expect(first.planDigest).not.toBe(desktop.planDigest);
294
294
  });
295
295
 
296
+ test('normalizes a malformed artifact URL to FirmwarePlanInvalid', () => {
297
+ let thrown: unknown;
298
+ try {
299
+ buildFirmwareUpdatePlan({
300
+ features: createFeatures({ deviceType: EDeviceType.Classic1s }),
301
+ firmwareType: EFirmwareType.Universal,
302
+ platform: 'native',
303
+ firmware: {
304
+ status: 'outdated',
305
+ release: {
306
+ url: 'not a url',
307
+ version: [3, 0, 0],
308
+ },
309
+ },
310
+ ble: noUpdate,
311
+ bootloader: noUpdate,
312
+ });
313
+ } catch (error) {
314
+ thrown = error;
315
+ }
316
+
317
+ expect(thrown).toMatchObject({
318
+ params: {
319
+ firmwareUpdateCode: 'FirmwarePlanInvalid',
320
+ },
321
+ });
322
+ });
323
+
296
324
  test('binds trusted artifact integrity metadata into the plan digest', () => {
297
325
  const createPlan = (fingerprint: string) =>
298
326
  buildFirmwareUpdatePlan({
@@ -0,0 +1,16 @@
1
+ import type { KaspaSignInputParams, KaspaSignOutputParams } from '../src/types';
2
+
3
+ const input: KaspaSignInputParams = {
4
+ path: "m/44'/111111'/0'/0/0",
5
+ prevTxId: 'aa'.repeat(32),
6
+ outputIndex: 0,
7
+ sequenceNumber: 0,
8
+ output: { satoshis: 200000 },
9
+ };
10
+
11
+ const output: KaspaSignOutputParams = {
12
+ satoshis: 100000,
13
+ address: 'kaspa:example',
14
+ };
15
+
16
+ export { input, output };