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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (693) hide show
  1. package/__tests__/AllNetworkGetAddressBase.tracing.test.ts +155 -0
  2. package/__tests__/DeviceCommands.test.ts +517 -0
  3. package/__tests__/DeviceEventRegistration.test.ts +49 -0
  4. package/__tests__/chain-params-onekey-compatibility.test.ts +229 -0
  5. package/__tests__/check-all-firmware-release-protocol-v2.test.ts +282 -0
  6. package/__tests__/connectSettings.test.ts +19 -0
  7. package/__tests__/core-dispose.test.ts +34 -0
  8. package/__tests__/core-error-output.test.ts +39 -0
  9. package/__tests__/device-features-state.test.ts +78 -0
  10. package/__tests__/device-identity.test.ts +52 -0
  11. package/__tests__/device-lifecycle-events.test.ts +249 -0
  12. package/__tests__/device-pool-state.test.ts +144 -0
  13. package/__tests__/device-settings.test.ts +416 -0
  14. package/__tests__/device-state-contract.test.ts +27 -0
  15. package/__tests__/device-state-events.test.ts +286 -0
  16. package/__tests__/device-state-mapper.test.ts +261 -0
  17. package/__tests__/device-state-projector.test.ts +94 -0
  18. package/__tests__/device-state-store.test.ts +82 -0
  19. package/__tests__/device-utils.test.ts +107 -0
  20. package/__tests__/device-wallet-session-store.test.ts +478 -0
  21. package/__tests__/deviceFeaturesUtils.test.ts +39 -0
  22. package/__tests__/deviceSettings.test.ts +103 -0
  23. package/__tests__/deviceUploadNft.test.ts +187 -0
  24. package/__tests__/evmLedgerLegacySafety.test.ts +12 -6
  25. package/__tests__/evmSignTransaction.test.ts +69 -0
  26. package/__tests__/evmSignTypedData.test.ts +80 -0
  27. package/__tests__/filesystemValidation.test.ts +53 -0
  28. package/__tests__/firmware-update/firmware-update-v2-download-before-boot.test.ts +402 -0
  29. package/__tests__/get-device-state.test.ts +578 -0
  30. package/__tests__/homescreen.test.ts +64 -0
  31. package/__tests__/kaspa-public-types.type-test.ts +16 -0
  32. package/__tests__/kaspa-use-tweak-pro2.test.ts +20 -0
  33. package/__tests__/kaspaSignTransaction.test.ts +601 -0
  34. package/__tests__/known-device-public-types.type-test.ts +3 -0
  35. package/__tests__/logBlockEvent.test.ts +128 -1
  36. package/__tests__/method-protocol-support.test.ts +113 -0
  37. package/__tests__/networkUtils.test.ts +406 -0
  38. package/__tests__/open-wallet-session-error-response.test.ts +43 -0
  39. package/__tests__/open-wallet-session.test.ts +1609 -0
  40. package/__tests__/pro2Nft.test.ts +108 -0
  41. package/__tests__/pro2Wallpaper.test.ts +39 -0
  42. package/__tests__/protocol-v2-bootloader-mode.test.ts +37 -0
  43. package/__tests__/protocol-v2-firmware-targets.test.ts +37 -0
  44. package/__tests__/protocol-v2-ping.test.ts +28 -0
  45. package/__tests__/protocol-v2-ui-lifecycle.test.ts +56 -0
  46. package/__tests__/protocol-v2-unlock-policy.test.ts +96 -0
  47. package/__tests__/protocol-v2.test.ts +5748 -2387
  48. package/__tests__/protocolV2FileWrite.test.ts +92 -0
  49. package/__tests__/protocolV2UiInteraction.test.ts +266 -0
  50. package/__tests__/public-device-state-api.test.ts +275 -0
  51. package/__tests__/public-pro2-api-boundary.test.ts +107 -0
  52. package/__tests__/refresh-device-state.test.ts +101 -0
  53. package/__tests__/request-context-logging.test.ts +16 -0
  54. package/__tests__/search-devices.test.ts +136 -0
  55. package/__tests__/tron-sign-message-init.test.ts +74 -0
  56. package/__tests__/uiProgressThrottle.test.ts +74 -0
  57. package/dist/api/BaseMethod.d.ts +16 -1
  58. package/dist/api/BaseMethod.d.ts.map +1 -1
  59. package/dist/api/CheckAllFirmwareRelease.d.ts +24 -1
  60. package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
  61. package/dist/api/CheckBootloaderRelease.d.ts.map +1 -1
  62. package/dist/api/CheckFirmwareRelease.d.ts.map +1 -1
  63. package/dist/api/CipherKeyValue.d.ts +1 -0
  64. package/dist/api/CipherKeyValue.d.ts.map +1 -1
  65. package/dist/api/ClearSessionCache.d.ts +9 -0
  66. package/dist/api/ClearSessionCache.d.ts.map +1 -0
  67. package/dist/api/DirList.d.ts +1 -0
  68. package/dist/api/DirList.d.ts.map +1 -1
  69. package/dist/api/DirMake.d.ts +1 -0
  70. package/dist/api/DirMake.d.ts.map +1 -1
  71. package/dist/api/DirRemove.d.ts +1 -0
  72. package/dist/api/DirRemove.d.ts.map +1 -1
  73. package/dist/api/FileDelete.d.ts +1 -0
  74. package/dist/api/FileDelete.d.ts.map +1 -1
  75. package/dist/api/FileRead.d.ts +1 -0
  76. package/dist/api/FileRead.d.ts.map +1 -1
  77. package/dist/api/FileWrite.d.ts +2 -0
  78. package/dist/api/FileWrite.d.ts.map +1 -1
  79. package/dist/api/FirmwareUpdate.d.ts.map +1 -1
  80. package/dist/api/FirmwareUpdateV2.d.ts +2 -2
  81. package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
  82. package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
  83. package/dist/api/FirmwareUpdateV4.d.ts +23 -14
  84. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  85. package/dist/api/GetDeviceState.d.ts +8 -0
  86. package/dist/api/GetDeviceState.d.ts.map +1 -0
  87. package/dist/api/GetFeatures.d.ts +1 -1
  88. package/dist/api/GetFeatures.d.ts.map +1 -1
  89. package/dist/api/GetOnekeyFeatures.d.ts.map +1 -1
  90. package/dist/api/GetPassphraseState.d.ts +2 -6
  91. package/dist/api/GetPassphraseState.d.ts.map +1 -1
  92. package/dist/api/OpenWalletSession.d.ts +8 -0
  93. package/dist/api/OpenWalletSession.d.ts.map +1 -0
  94. package/dist/api/PathInfo.d.ts +1 -0
  95. package/dist/api/PathInfo.d.ts.map +1 -1
  96. package/dist/api/PromptWebDeviceAccess.d.ts.map +1 -1
  97. package/dist/api/SearchDevices.d.ts +3 -0
  98. package/dist/api/SearchDevices.d.ts.map +1 -1
  99. package/dist/api/UploadPortfolio.d.ts +17 -0
  100. package/dist/api/UploadPortfolio.d.ts.map +1 -0
  101. package/dist/api/alephium/AlephiumGetAddress.d.ts.map +1 -1
  102. package/dist/api/alephium/AlephiumSignMessage.d.ts.map +1 -1
  103. package/dist/api/alephium/AlephiumSignTransaction.d.ts.map +1 -1
  104. package/dist/api/algo/AlgoGetAddress.d.ts +1 -0
  105. package/dist/api/algo/AlgoGetAddress.d.ts.map +1 -1
  106. package/dist/api/algo/AlgoSignTransaction.d.ts +1 -0
  107. package/dist/api/algo/AlgoSignTransaction.d.ts.map +1 -1
  108. package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts +1 -0
  109. package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
  110. package/dist/api/aptos/AptosGetAddress.d.ts +1 -0
  111. package/dist/api/aptos/AptosGetAddress.d.ts.map +1 -1
  112. package/dist/api/aptos/AptosGetPublicKey.d.ts +1 -0
  113. package/dist/api/aptos/AptosGetPublicKey.d.ts.map +1 -1
  114. package/dist/api/aptos/AptosSignInMessage.d.ts +1 -0
  115. package/dist/api/aptos/AptosSignInMessage.d.ts.map +1 -1
  116. package/dist/api/aptos/AptosSignMessage.d.ts +1 -0
  117. package/dist/api/aptos/AptosSignMessage.d.ts.map +1 -1
  118. package/dist/api/aptos/AptosSignTransaction.d.ts +1 -0
  119. package/dist/api/aptos/AptosSignTransaction.d.ts.map +1 -1
  120. package/dist/api/benfen/BenfenGetAddress.d.ts.map +1 -1
  121. package/dist/api/benfen/BenfenGetPublicKey.d.ts.map +1 -1
  122. package/dist/api/benfen/BenfenSignMessage.d.ts.map +1 -1
  123. package/dist/api/benfen/BenfenSignTransaction.d.ts.map +1 -1
  124. package/dist/api/btc/BTCGetAddress.d.ts +1 -0
  125. package/dist/api/btc/BTCGetAddress.d.ts.map +1 -1
  126. package/dist/api/btc/BTCGetPublicKey.d.ts +1 -0
  127. package/dist/api/btc/BTCGetPublicKey.d.ts.map +1 -1
  128. package/dist/api/btc/BTCSignMessage.d.ts +1 -0
  129. package/dist/api/btc/BTCSignMessage.d.ts.map +1 -1
  130. package/dist/api/btc/BTCSignPsbt.d.ts +1 -0
  131. package/dist/api/btc/BTCSignPsbt.d.ts.map +1 -1
  132. package/dist/api/btc/BTCSignTransaction.d.ts +1 -0
  133. package/dist/api/btc/BTCSignTransaction.d.ts.map +1 -1
  134. package/dist/api/btc/BTCVerifyMessage.d.ts +1 -0
  135. package/dist/api/btc/BTCVerifyMessage.d.ts.map +1 -1
  136. package/dist/api/btc/helpers/versionLimit.d.ts +2 -0
  137. package/dist/api/btc/helpers/versionLimit.d.ts.map +1 -1
  138. package/dist/api/cardano/CardanoGetAddress.d.ts +1 -0
  139. package/dist/api/cardano/CardanoGetAddress.d.ts.map +1 -1
  140. package/dist/api/cardano/CardanoGetPublicKey.d.ts +1 -0
  141. package/dist/api/cardano/CardanoGetPublicKey.d.ts.map +1 -1
  142. package/dist/api/cardano/CardanoSignMessage.d.ts +1 -0
  143. package/dist/api/cardano/CardanoSignMessage.d.ts.map +1 -1
  144. package/dist/api/cardano/CardanoSignTransaction.d.ts +1 -0
  145. package/dist/api/cardano/CardanoSignTransaction.d.ts.map +1 -1
  146. package/dist/api/conflux/ConfluxGetAddress.d.ts +2 -0
  147. package/dist/api/conflux/ConfluxGetAddress.d.ts.map +1 -1
  148. package/dist/api/conflux/ConfluxSignMessage.d.ts +2 -0
  149. package/dist/api/conflux/ConfluxSignMessage.d.ts.map +1 -1
  150. package/dist/api/conflux/ConfluxSignMessageCIP23.d.ts +2 -0
  151. package/dist/api/conflux/ConfluxSignMessageCIP23.d.ts.map +1 -1
  152. package/dist/api/conflux/ConfluxSignTransaction.d.ts +2 -0
  153. package/dist/api/conflux/ConfluxSignTransaction.d.ts.map +1 -1
  154. package/dist/api/cosmos/CosmosGetAddress.d.ts +1 -0
  155. package/dist/api/cosmos/CosmosGetAddress.d.ts.map +1 -1
  156. package/dist/api/cosmos/CosmosGetPublicKey.d.ts +1 -0
  157. package/dist/api/cosmos/CosmosGetPublicKey.d.ts.map +1 -1
  158. package/dist/api/cosmos/CosmosSignTransaction.d.ts +1 -0
  159. package/dist/api/cosmos/CosmosSignTransaction.d.ts.map +1 -1
  160. package/dist/api/device/DeviceCancel.d.ts +1 -0
  161. package/dist/api/device/DeviceCancel.d.ts.map +1 -1
  162. package/dist/api/device/DeviceChangePin.d.ts +1 -0
  163. package/dist/api/device/DeviceChangePin.d.ts.map +1 -1
  164. package/dist/api/device/DeviceFullyUploadResource.d.ts +1 -2
  165. package/dist/api/device/DeviceFullyUploadResource.d.ts.map +1 -1
  166. package/dist/api/device/DeviceLock.d.ts +1 -0
  167. package/dist/api/device/DeviceLock.d.ts.map +1 -1
  168. package/dist/api/device/DeviceRebootToBoardloader.d.ts +1 -0
  169. package/dist/api/device/DeviceRebootToBoardloader.d.ts.map +1 -1
  170. package/dist/api/device/DeviceRebootToBootloader.d.ts +1 -0
  171. package/dist/api/device/DeviceRebootToBootloader.d.ts.map +1 -1
  172. package/dist/api/device/DeviceSettings.d.ts +1 -0
  173. package/dist/api/device/DeviceSettings.d.ts.map +1 -1
  174. package/dist/api/device/DeviceSupportFeatures.d.ts +1 -0
  175. package/dist/api/device/DeviceSupportFeatures.d.ts.map +1 -1
  176. package/dist/api/device/DeviceUnlock.d.ts +1 -0
  177. package/dist/api/device/DeviceUnlock.d.ts.map +1 -1
  178. package/dist/api/device/DeviceUpdateBootloader.d.ts.map +1 -1
  179. package/dist/api/device/DeviceWipe.d.ts +1 -0
  180. package/dist/api/device/DeviceWipe.d.ts.map +1 -1
  181. package/dist/api/device/PreInitialize.d.ts +1 -0
  182. package/dist/api/device/PreInitialize.d.ts.map +1 -1
  183. package/dist/api/dynex/DnxGetAddress.d.ts.map +1 -1
  184. package/dist/api/dynex/DnxSignTransaction.d.ts.map +1 -1
  185. package/dist/api/evm/EVMGetAddress.d.ts +1 -0
  186. package/dist/api/evm/EVMGetAddress.d.ts.map +1 -1
  187. package/dist/api/evm/EVMGetPublicKey.d.ts +1 -0
  188. package/dist/api/evm/EVMGetPublicKey.d.ts.map +1 -1
  189. package/dist/api/evm/EVMSignMessage.d.ts +1 -0
  190. package/dist/api/evm/EVMSignMessage.d.ts.map +1 -1
  191. package/dist/api/evm/EVMSignMessageEIP712.d.ts.map +1 -1
  192. package/dist/api/evm/EVMSignTransaction.d.ts +1 -0
  193. package/dist/api/evm/EVMSignTransaction.d.ts.map +1 -1
  194. package/dist/api/evm/EVMSignTypedData.d.ts +1 -0
  195. package/dist/api/evm/EVMSignTypedData.d.ts.map +1 -1
  196. package/dist/api/evm/EVMVerifyMessage.d.ts +1 -0
  197. package/dist/api/evm/EVMVerifyMessage.d.ts.map +1 -1
  198. package/dist/api/evm/protocol.d.ts +3 -0
  199. package/dist/api/evm/protocol.d.ts.map +1 -0
  200. package/dist/api/filecoin/FilecoinGetAddress.d.ts +1 -0
  201. package/dist/api/filecoin/FilecoinGetAddress.d.ts.map +1 -1
  202. package/dist/api/filecoin/FilecoinSignTransaction.d.ts +1 -0
  203. package/dist/api/filecoin/FilecoinSignTransaction.d.ts.map +1 -1
  204. package/dist/api/firmware/getBinary.d.ts +8 -4
  205. package/dist/api/firmware/getBinary.d.ts.map +1 -1
  206. package/dist/api/helpers/filesystemValidation.d.ts +3 -0
  207. package/dist/api/helpers/filesystemValidation.d.ts.map +1 -1
  208. package/dist/api/helpers/paramsValidator.d.ts +1 -0
  209. package/dist/api/helpers/paramsValidator.d.ts.map +1 -1
  210. package/dist/api/helpers/protocolV2FileWrite.d.ts +35 -0
  211. package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -0
  212. package/dist/api/index.d.ts +8 -25
  213. package/dist/api/index.d.ts.map +1 -1
  214. package/dist/api/kaspa/KaspaGetAddress.d.ts +4 -0
  215. package/dist/api/kaspa/KaspaGetAddress.d.ts.map +1 -1
  216. package/dist/api/kaspa/KaspaSignTransaction.d.ts +9 -1
  217. package/dist/api/kaspa/KaspaSignTransaction.d.ts.map +1 -1
  218. package/dist/api/kaspa/helpers/TransferSerialize.d.ts.map +1 -1
  219. package/dist/api/lightning/LnurlAuth.d.ts +0 -4
  220. package/dist/api/lightning/LnurlAuth.d.ts.map +1 -1
  221. package/dist/api/near/NearGetAddress.d.ts +1 -0
  222. package/dist/api/near/NearGetAddress.d.ts.map +1 -1
  223. package/dist/api/near/NearSignTransaction.d.ts +1 -0
  224. package/dist/api/near/NearSignTransaction.d.ts.map +1 -1
  225. package/dist/api/nem/NEMGetAddress.d.ts +1 -0
  226. package/dist/api/nem/NEMGetAddress.d.ts.map +1 -1
  227. package/dist/api/nem/NEMSignTransaction.d.ts +1 -0
  228. package/dist/api/nem/NEMSignTransaction.d.ts.map +1 -1
  229. package/dist/api/neo/NeoGetAddress.d.ts.map +1 -1
  230. package/dist/api/neo/NeoSignTransaction.d.ts.map +1 -1
  231. package/dist/api/nervos/NervosGetAddress.d.ts.map +1 -1
  232. package/dist/api/nervos/NervosSignTransaction.d.ts.map +1 -1
  233. package/dist/api/nexa/NexaGetAddress.d.ts.map +1 -1
  234. package/dist/api/nexa/NexaSignTransaction.d.ts +1 -0
  235. package/dist/api/nexa/NexaSignTransaction.d.ts.map +1 -1
  236. package/dist/api/nostr/NostrDecryptMessage.d.ts +1 -0
  237. package/dist/api/nostr/NostrDecryptMessage.d.ts.map +1 -1
  238. package/dist/api/nostr/NostrEncryptMessage.d.ts +1 -0
  239. package/dist/api/nostr/NostrEncryptMessage.d.ts.map +1 -1
  240. package/dist/api/nostr/NostrGetPublicKey.d.ts +1 -0
  241. package/dist/api/nostr/NostrGetPublicKey.d.ts.map +1 -1
  242. package/dist/api/nostr/NostrSignEvent.d.ts +1 -0
  243. package/dist/api/nostr/NostrSignEvent.d.ts.map +1 -1
  244. package/dist/api/nostr/NostrSignSchnorr.d.ts +1 -0
  245. package/dist/api/nostr/NostrSignSchnorr.d.ts.map +1 -1
  246. package/dist/api/polkadot/PolkadotGetAddress.d.ts +1 -0
  247. package/dist/api/polkadot/PolkadotGetAddress.d.ts.map +1 -1
  248. package/dist/api/polkadot/PolkadotSignTransaction.d.ts +1 -0
  249. package/dist/api/polkadot/PolkadotSignTransaction.d.ts.map +1 -1
  250. package/dist/api/protocol-v2/DeviceFactoryInfoGet.d.ts +1 -0
  251. package/dist/api/protocol-v2/DeviceFactoryInfoGet.d.ts.map +1 -1
  252. package/dist/api/protocol-v2/DeviceFactoryInfoSet.d.ts +1 -0
  253. package/dist/api/protocol-v2/DeviceFactoryInfoSet.d.ts.map +1 -1
  254. package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts +1 -0
  255. package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts.map +1 -1
  256. package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts +4 -2
  257. package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts.map +1 -1
  258. package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts +7 -0
  259. package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts.map +1 -0
  260. package/dist/api/protocol-v2/DeviceInfoGet.d.ts +1 -1
  261. package/dist/api/protocol-v2/DeviceInfoGet.d.ts.map +1 -1
  262. package/dist/api/protocol-v2/DeviceReboot.d.ts +1 -0
  263. package/dist/api/protocol-v2/DeviceReboot.d.ts.map +1 -1
  264. package/dist/api/protocol-v2/DeviceStatusGet.d.ts +7 -0
  265. package/dist/api/protocol-v2/DeviceStatusGet.d.ts.map +1 -0
  266. package/dist/api/protocol-v2/DeviceUploadNft.d.ts +30 -0
  267. package/dist/api/protocol-v2/DeviceUploadNft.d.ts.map +1 -0
  268. package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts +27 -0
  269. package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts.map +1 -0
  270. package/dist/api/protocol-v2/FilesystemFormat.d.ts +1 -0
  271. package/dist/api/protocol-v2/FilesystemFormat.d.ts.map +1 -1
  272. package/dist/api/protocol-v2/FilesystemPermissionFix.d.ts +1 -0
  273. package/dist/api/protocol-v2/FilesystemPermissionFix.d.ts.map +1 -1
  274. package/dist/api/protocol-v2/Ping.d.ts +3 -0
  275. package/dist/api/protocol-v2/Ping.d.ts.map +1 -1
  276. package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts +1 -0
  277. package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts.map +1 -1
  278. package/dist/api/protocol-v2/helpers.d.ts +4 -1
  279. package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
  280. package/dist/api/scdo/ScdoGetAddress.d.ts.map +1 -1
  281. package/dist/api/scdo/ScdoSignMessage.d.ts.map +1 -1
  282. package/dist/api/scdo/ScdoSignTransaction.d.ts.map +1 -1
  283. package/dist/api/solana/SolGetAddress.d.ts +1 -0
  284. package/dist/api/solana/SolGetAddress.d.ts.map +1 -1
  285. package/dist/api/solana/SolSignMessage.d.ts +1 -0
  286. package/dist/api/solana/SolSignMessage.d.ts.map +1 -1
  287. package/dist/api/solana/SolSignOffchainMessage.d.ts +1 -0
  288. package/dist/api/solana/SolSignOffchainMessage.d.ts.map +1 -1
  289. package/dist/api/solana/SolSignTransaction.d.ts +1 -0
  290. package/dist/api/solana/SolSignTransaction.d.ts.map +1 -1
  291. package/dist/api/starcoin/StarcoinGetAddress.d.ts +1 -0
  292. package/dist/api/starcoin/StarcoinGetAddress.d.ts.map +1 -1
  293. package/dist/api/starcoin/StarcoinGetPublicKey.d.ts +1 -0
  294. package/dist/api/starcoin/StarcoinGetPublicKey.d.ts.map +1 -1
  295. package/dist/api/starcoin/StarcoinSignMessage.d.ts +1 -0
  296. package/dist/api/starcoin/StarcoinSignMessage.d.ts.map +1 -1
  297. package/dist/api/starcoin/StarcoinSignTransaction.d.ts +1 -0
  298. package/dist/api/starcoin/StarcoinSignTransaction.d.ts.map +1 -1
  299. package/dist/api/starcoin/StarcoinVerifyMessage.d.ts +1 -0
  300. package/dist/api/starcoin/StarcoinVerifyMessage.d.ts.map +1 -1
  301. package/dist/api/stellar/StellarGetAddress.d.ts +1 -2
  302. package/dist/api/stellar/StellarGetAddress.d.ts.map +1 -1
  303. package/dist/api/stellar/StellarSignTransaction.d.ts +1 -2
  304. package/dist/api/stellar/StellarSignTransaction.d.ts.map +1 -1
  305. package/dist/api/sui/SuiGetAddress.d.ts +1 -0
  306. package/dist/api/sui/SuiGetAddress.d.ts.map +1 -1
  307. package/dist/api/sui/SuiGetPublicKey.d.ts +1 -0
  308. package/dist/api/sui/SuiGetPublicKey.d.ts.map +1 -1
  309. package/dist/api/sui/SuiSignMessage.d.ts +1 -0
  310. package/dist/api/sui/SuiSignMessage.d.ts.map +1 -1
  311. package/dist/api/sui/SuiSignTransaction.d.ts +1 -0
  312. package/dist/api/sui/SuiSignTransaction.d.ts.map +1 -1
  313. package/dist/api/ton/TonGetAddress.d.ts +1 -0
  314. package/dist/api/ton/TonGetAddress.d.ts.map +1 -1
  315. package/dist/api/ton/TonSignData.d.ts +1 -0
  316. package/dist/api/ton/TonSignData.d.ts.map +1 -1
  317. package/dist/api/ton/TonSignMessage.d.ts +1 -0
  318. package/dist/api/ton/TonSignMessage.d.ts.map +1 -1
  319. package/dist/api/ton/TonSignProof.d.ts +1 -0
  320. package/dist/api/ton/TonSignProof.d.ts.map +1 -1
  321. package/dist/api/tron/TronGetAddress.d.ts +1 -0
  322. package/dist/api/tron/TronGetAddress.d.ts.map +1 -1
  323. package/dist/api/tron/TronSignMessage.d.ts +5 -0
  324. package/dist/api/tron/TronSignMessage.d.ts.map +1 -1
  325. package/dist/api/tron/TronSignTransaction.d.ts +1 -0
  326. package/dist/api/tron/TronSignTransaction.d.ts.map +1 -1
  327. package/dist/api/utils.d.ts +2 -1
  328. package/dist/api/utils.d.ts.map +1 -1
  329. package/dist/api/xrp/XrpGetAddress.d.ts +1 -0
  330. package/dist/api/xrp/XrpGetAddress.d.ts.map +1 -1
  331. package/dist/api/xrp/XrpSignTransaction.d.ts +1 -0
  332. package/dist/api/xrp/XrpSignTransaction.d.ts.map +1 -1
  333. package/dist/constants/index.d.ts +1 -1
  334. package/dist/constants/index.d.ts.map +1 -1
  335. package/dist/core/RequestQueue.d.ts.map +1 -1
  336. package/dist/core/deviceEventRegistration.d.ts +13 -0
  337. package/dist/core/deviceEventRegistration.d.ts.map +1 -0
  338. package/dist/core/index.d.ts +3 -1
  339. package/dist/core/index.d.ts.map +1 -1
  340. package/dist/data-manager/connectSettings.d.ts.map +1 -1
  341. package/dist/device/Device.d.ts +64 -16
  342. package/dist/device/Device.d.ts.map +1 -1
  343. package/dist/device/DeviceCommands.d.ts +8 -6
  344. package/dist/device/DeviceCommands.d.ts.map +1 -1
  345. package/dist/device/DeviceConnector.d.ts +1 -1
  346. package/dist/device/DeviceConnector.d.ts.map +1 -1
  347. package/dist/device/DeviceFeaturesState.d.ts +3 -0
  348. package/dist/device/DeviceFeaturesState.d.ts.map +1 -0
  349. package/dist/device/DevicePool.d.ts +5 -2
  350. package/dist/device/DevicePool.d.ts.map +1 -1
  351. package/dist/device/DeviceStateMapper.d.ts +13 -0
  352. package/dist/device/DeviceStateMapper.d.ts.map +1 -0
  353. package/dist/device/DeviceStateProjector.d.ts +7 -0
  354. package/dist/device/DeviceStateProjector.d.ts.map +1 -0
  355. package/dist/device/DeviceStateStore.d.ts +21 -0
  356. package/dist/device/DeviceStateStore.d.ts.map +1 -0
  357. package/dist/device/DeviceWalletSessionStore.d.ts +27 -0
  358. package/dist/device/DeviceWalletSessionStore.d.ts.map +1 -0
  359. package/dist/device/cloneDeviceState.d.ts +2 -0
  360. package/dist/device/cloneDeviceState.d.ts.map +1 -0
  361. package/dist/device/deviceIdentity.d.ts +5 -0
  362. package/dist/device/deviceIdentity.d.ts.map +1 -0
  363. package/dist/deviceProfile/buildDeviceFeatures.d.ts +9 -3
  364. package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -1
  365. package/dist/deviceProfile/index.d.ts +0 -1
  366. package/dist/deviceProfile/index.d.ts.map +1 -1
  367. package/dist/deviceProfile/protocolV2DeviceIdentity.d.ts +7 -0
  368. package/dist/deviceProfile/protocolV2DeviceIdentity.d.ts.map +1 -0
  369. package/dist/events/device.d.ts +16 -2
  370. package/dist/events/device.d.ts.map +1 -1
  371. package/dist/events/logBlockEvent.d.ts +2 -0
  372. package/dist/events/logBlockEvent.d.ts.map +1 -1
  373. package/dist/events/ui-request.d.ts +46 -4
  374. package/dist/events/ui-request.d.ts.map +1 -1
  375. package/dist/index.d.ts +1442 -712
  376. package/dist/index.js +7497 -3705
  377. package/dist/inject.d.ts.map +1 -1
  378. package/dist/protocols/protocol-v2/deviceSession.d.ts +7 -0
  379. package/dist/protocols/protocol-v2/deviceSession.d.ts.map +1 -0
  380. package/dist/protocols/protocol-v2/features.d.ts +25 -17
  381. package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
  382. package/dist/protocols/protocol-v2/firmware.d.ts +1 -0
  383. package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -1
  384. package/dist/protocols/protocol-v2/index.d.ts +3 -2
  385. package/dist/protocols/protocol-v2/index.d.ts.map +1 -1
  386. package/dist/protocols/protocol-v2/settingsUnlockPolicy.d.ts +17 -0
  387. package/dist/protocols/protocol-v2/settingsUnlockPolicy.d.ts.map +1 -0
  388. package/dist/protocols/protocol-v2/uiInteraction.d.ts +39 -0
  389. package/dist/protocols/protocol-v2/uiInteraction.d.ts.map +1 -0
  390. package/dist/protocols/protocol-v2/unlockPolicy.d.ts +2 -0
  391. package/dist/protocols/protocol-v2/unlockPolicy.d.ts.map +1 -0
  392. package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts +22 -0
  393. package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts.map +1 -0
  394. package/dist/protocols/protocol-v2/walletSession.d.ts +25 -0
  395. package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -0
  396. package/dist/types/api/checkAllFirmwareRelease.d.ts +25 -4
  397. package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
  398. package/dist/types/api/deviceSettings.d.ts +11 -2
  399. package/dist/types/api/deviceSettings.d.ts.map +1 -1
  400. package/dist/types/api/deviceUnlock.d.ts +1 -1
  401. package/dist/types/api/deviceUnlock.d.ts.map +1 -1
  402. package/dist/types/api/export.d.ts +3 -2
  403. package/dist/types/api/export.d.ts.map +1 -1
  404. package/dist/types/api/firmwareUpdate.d.ts +6 -1
  405. package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
  406. package/dist/types/api/getDeviceState.d.ts +12 -0
  407. package/dist/types/api/getDeviceState.d.ts.map +1 -0
  408. package/dist/types/api/getFeatures.d.ts.map +1 -1
  409. package/dist/types/api/getOnekeyFeatures.d.ts.map +1 -1
  410. package/dist/types/api/getPassphraseState.d.ts +2 -10
  411. package/dist/types/api/getPassphraseState.d.ts.map +1 -1
  412. package/dist/types/api/index.d.ts +19 -30
  413. package/dist/types/api/index.d.ts.map +1 -1
  414. package/dist/types/api/kaspaSignTransaction.d.ts +42 -4
  415. package/dist/types/api/kaspaSignTransaction.d.ts.map +1 -1
  416. package/dist/types/api/openWalletSession.d.ts +35 -0
  417. package/dist/types/api/openWalletSession.d.ts.map +1 -0
  418. package/dist/types/api/protocolV2.d.ts +18 -84
  419. package/dist/types/api/protocolV2.d.ts.map +1 -1
  420. package/dist/types/api/sessionCache.d.ts +13 -0
  421. package/dist/types/api/sessionCache.d.ts.map +1 -0
  422. package/dist/types/device.d.ts +132 -8
  423. package/dist/types/device.d.ts.map +1 -1
  424. package/dist/types/params.d.ts.map +1 -1
  425. package/dist/types/settings.d.ts +7 -14
  426. package/dist/types/settings.d.ts.map +1 -1
  427. package/dist/utils/assets.d.ts +2 -1
  428. package/dist/utils/assets.d.ts.map +1 -1
  429. package/dist/utils/deviceFeaturesCompat.d.ts +13 -0
  430. package/dist/utils/deviceFeaturesCompat.d.ts.map +1 -0
  431. package/dist/utils/deviceFeaturesUtils.d.ts +8 -3
  432. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  433. package/dist/utils/deviceInfoUtils.d.ts +9 -9
  434. package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
  435. package/dist/utils/deviceSettings.d.ts +38 -7
  436. package/dist/utils/deviceSettings.d.ts.map +1 -1
  437. package/dist/utils/deviceVersionUtils.d.ts +7 -5
  438. package/dist/utils/deviceVersionUtils.d.ts.map +1 -1
  439. package/dist/utils/homescreen.d.ts +4 -0
  440. package/dist/utils/homescreen.d.ts.map +1 -1
  441. package/dist/utils/index.d.ts +6 -3
  442. package/dist/utils/index.d.ts.map +1 -1
  443. package/dist/utils/networkUtils.d.ts +10 -1
  444. package/dist/utils/networkUtils.d.ts.map +1 -1
  445. package/dist/utils/patch.d.ts +1 -1
  446. package/dist/utils/patch.d.ts.map +1 -1
  447. package/dist/utils/pro2Nft.d.ts +29 -0
  448. package/dist/utils/pro2Nft.d.ts.map +1 -0
  449. package/dist/utils/pro2Wallpaper.d.ts +22 -0
  450. package/dist/utils/pro2Wallpaper.d.ts.map +1 -0
  451. package/dist/utils/tracing.d.ts.map +1 -1
  452. package/dist/utils/uiProgressThrottle.d.ts +3 -0
  453. package/dist/utils/uiProgressThrottle.d.ts.map +1 -0
  454. package/package.json +4 -4
  455. package/src/api/BaseMethod.ts +53 -20
  456. package/src/api/CheckAllFirmwareRelease.ts +296 -1
  457. package/src/api/CheckBootloaderRelease.ts +1 -2
  458. package/src/api/CheckFirmwareRelease.ts +1 -2
  459. package/src/api/CipherKeyValue.ts +4 -0
  460. package/src/api/ClearSessionCache.ts +32 -0
  461. package/src/api/DirList.ts +9 -4
  462. package/src/api/DirMake.ts +7 -4
  463. package/src/api/DirRemove.ts +7 -4
  464. package/src/api/FileDelete.ts +7 -4
  465. package/src/api/FileRead.ts +15 -9
  466. package/src/api/FileWrite.ts +26 -181
  467. package/src/api/FirmwareUpdate.ts +11 -12
  468. package/src/api/FirmwareUpdateV2.ts +132 -52
  469. package/src/api/FirmwareUpdateV3.ts +3 -11
  470. package/src/api/FirmwareUpdateV4.ts +693 -535
  471. package/src/api/GetDeviceState.ts +59 -0
  472. package/src/api/GetFeatures.ts +6 -4
  473. package/src/api/GetOnekeyFeatures.ts +1 -75
  474. package/src/api/GetPassphraseState.ts +36 -21
  475. package/src/api/OpenWalletSession.ts +251 -0
  476. package/src/api/PathInfo.ts +9 -4
  477. package/src/api/PromptWebDeviceAccess.ts +2 -7
  478. package/src/api/SearchDevices.ts +29 -4
  479. package/src/api/UploadPortfolio.ts +40 -0
  480. package/src/api/alephium/AlephiumGetAddress.ts +0 -4
  481. package/src/api/alephium/AlephiumSignMessage.ts +0 -4
  482. package/src/api/alephium/AlephiumSignTransaction.ts +2 -6
  483. package/src/api/algo/AlgoGetAddress.ts +4 -0
  484. package/src/api/algo/AlgoSignTransaction.ts +4 -0
  485. package/src/api/allnetwork/AllNetworkGetAddressBase.ts +41 -32
  486. package/src/api/aptos/AptosGetAddress.ts +4 -0
  487. package/src/api/aptos/AptosGetPublicKey.ts +4 -0
  488. package/src/api/aptos/AptosSignInMessage.ts +4 -0
  489. package/src/api/aptos/AptosSignMessage.ts +4 -0
  490. package/src/api/aptos/AptosSignTransaction.ts +4 -0
  491. package/src/api/benfen/BenfenGetAddress.ts +11 -7
  492. package/src/api/benfen/BenfenGetPublicKey.ts +0 -4
  493. package/src/api/benfen/BenfenSignMessage.ts +0 -4
  494. package/src/api/benfen/BenfenSignTransaction.ts +0 -4
  495. package/src/api/btc/BTCGetAddress.ts +8 -1
  496. package/src/api/btc/BTCGetPublicKey.ts +9 -2
  497. package/src/api/btc/BTCSignMessage.ts +8 -1
  498. package/src/api/btc/BTCSignPsbt.ts +4 -0
  499. package/src/api/btc/BTCSignTransaction.ts +8 -1
  500. package/src/api/btc/BTCVerifyMessage.ts +8 -1
  501. package/src/api/btc/helpers/versionLimit.ts +7 -4
  502. package/src/api/cardano/CardanoGetAddress.ts +4 -0
  503. package/src/api/cardano/CardanoGetPublicKey.ts +4 -0
  504. package/src/api/cardano/CardanoSignMessage.ts +5 -1
  505. package/src/api/cardano/CardanoSignTransaction.ts +5 -1
  506. package/src/api/conflux/ConfluxGetAddress.ts +6 -0
  507. package/src/api/conflux/ConfluxSignMessage.ts +6 -0
  508. package/src/api/conflux/ConfluxSignMessageCIP23.ts +6 -0
  509. package/src/api/conflux/ConfluxSignTransaction.ts +8 -5
  510. package/src/api/cosmos/CosmosGetAddress.ts +4 -0
  511. package/src/api/cosmos/CosmosGetPublicKey.ts +4 -0
  512. package/src/api/cosmos/CosmosSignTransaction.ts +4 -0
  513. package/src/api/device/DeviceCancel.ts +5 -0
  514. package/src/api/device/DeviceChangePin.ts +28 -0
  515. package/src/api/device/DeviceFullyUploadResource.ts +4 -5
  516. package/src/api/device/DeviceLock.ts +5 -0
  517. package/src/api/device/DeviceRebootToBoardloader.ts +5 -0
  518. package/src/api/device/DeviceRebootToBootloader.ts +5 -0
  519. package/src/api/device/DeviceSettings.ts +194 -1
  520. package/src/api/device/DeviceSupportFeatures.ts +4 -0
  521. package/src/api/device/DeviceUnlock.ts +14 -1
  522. package/src/api/device/DeviceUpdateBootloader.ts +1 -2
  523. package/src/api/device/DeviceWipe.ts +25 -0
  524. package/src/api/device/PreInitialize.ts +4 -0
  525. package/src/api/dynex/DnxGetAddress.ts +0 -6
  526. package/src/api/dynex/DnxSignTransaction.ts +0 -6
  527. package/src/api/evm/EVMGetAddress.ts +6 -2
  528. package/src/api/evm/EVMGetPublicKey.ts +6 -2
  529. package/src/api/evm/EVMSignMessage.ts +6 -2
  530. package/src/api/evm/EVMSignMessageEIP712.ts +1 -11
  531. package/src/api/evm/EVMSignTransaction.ts +6 -2
  532. package/src/api/evm/EVMSignTypedData.ts +42 -50
  533. package/src/api/evm/EVMVerifyMessage.ts +6 -2
  534. package/src/api/evm/legacyV1/getAddress.ts +2 -2
  535. package/src/api/evm/legacyV1/getPublicKey.ts +2 -2
  536. package/src/api/evm/legacyV1/signMessage.ts +2 -2
  537. package/src/api/evm/legacyV1/signTypedData.ts +2 -2
  538. package/src/api/evm/legacyV1/signTypedHash.ts +2 -2
  539. package/src/api/evm/legacyV1/verifyMessage.ts +2 -2
  540. package/src/api/evm/protocol.ts +6 -0
  541. package/src/api/filecoin/FilecoinGetAddress.ts +4 -0
  542. package/src/api/filecoin/FilecoinSignTransaction.ts +4 -0
  543. package/src/api/firmware/FirmwareUpdateBaseMethod.ts +3 -3
  544. package/src/api/firmware/getBinary.ts +8 -3
  545. package/src/api/helpers/batchGetPublickeys.ts +2 -2
  546. package/src/api/helpers/filesystemValidation.ts +61 -0
  547. package/src/api/helpers/paramsValidator.ts +1 -1
  548. package/src/api/helpers/protocolV2FileWrite.ts +206 -0
  549. package/src/api/index.ts +9 -26
  550. package/src/api/kaspa/KaspaGetAddress.ts +7 -0
  551. package/src/api/kaspa/KaspaSignTransaction.ts +380 -29
  552. package/src/api/kaspa/helpers/TransferSerialize.ts +17 -7
  553. package/src/api/lightning/LnurlAuth.ts +0 -4
  554. package/src/api/near/NearGetAddress.ts +4 -0
  555. package/src/api/near/NearSignTransaction.ts +4 -0
  556. package/src/api/nem/NEMGetAddress.ts +4 -0
  557. package/src/api/nem/NEMSignTransaction.ts +4 -0
  558. package/src/api/neo/NeoGetAddress.ts +0 -4
  559. package/src/api/neo/NeoSignTransaction.ts +0 -4
  560. package/src/api/nervos/NervosGetAddress.ts +0 -4
  561. package/src/api/nervos/NervosSignTransaction.ts +2 -6
  562. package/src/api/nexa/NexaGetAddress.ts +0 -4
  563. package/src/api/nexa/NexaSignTransaction.ts +3 -5
  564. package/src/api/nostr/NostrDecryptMessage.ts +4 -0
  565. package/src/api/nostr/NostrEncryptMessage.ts +4 -0
  566. package/src/api/nostr/NostrGetPublicKey.ts +4 -0
  567. package/src/api/nostr/NostrSignEvent.ts +4 -0
  568. package/src/api/nostr/NostrSignSchnorr.ts +4 -0
  569. package/src/api/polkadot/PolkadotGetAddress.ts +4 -0
  570. package/src/api/polkadot/PolkadotSignTransaction.ts +4 -0
  571. package/src/api/protocol-v2/DeviceFactoryInfoGet.ts +5 -2
  572. package/src/api/protocol-v2/DeviceFactoryInfoSet.ts +5 -2
  573. package/src/api/protocol-v2/DeviceFirmwareUpdate.ts +8 -5
  574. package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +43 -5
  575. package/src/api/protocol-v2/DeviceGetOnboardingStatus.ts +21 -0
  576. package/src/api/protocol-v2/DeviceInfoGet.ts +8 -15
  577. package/src/api/protocol-v2/DeviceReboot.ts +7 -3
  578. package/src/api/protocol-v2/DeviceStatusGet.ts +19 -0
  579. package/src/api/protocol-v2/DeviceUploadNft.ts +166 -0
  580. package/src/api/protocol-v2/DeviceUploadWallpaper.ts +134 -0
  581. package/src/api/protocol-v2/FilesystemFormat.ts +9 -3
  582. package/src/api/protocol-v2/FilesystemPermissionFix.ts +5 -2
  583. package/src/api/protocol-v2/Ping.ts +37 -3
  584. package/src/api/protocol-v2/ProtocolInfoRequest.ts +8 -3
  585. package/src/api/protocol-v2/helpers.ts +21 -16
  586. package/src/api/scdo/ScdoGetAddress.ts +0 -4
  587. package/src/api/scdo/ScdoSignMessage.ts +0 -4
  588. package/src/api/scdo/ScdoSignTransaction.ts +0 -4
  589. package/src/api/solana/SolGetAddress.ts +4 -0
  590. package/src/api/solana/SolSignMessage.ts +4 -0
  591. package/src/api/solana/SolSignOffchainMessage.ts +4 -0
  592. package/src/api/solana/SolSignTransaction.ts +4 -0
  593. package/src/api/starcoin/StarcoinGetAddress.ts +4 -0
  594. package/src/api/starcoin/StarcoinGetPublicKey.ts +4 -0
  595. package/src/api/starcoin/StarcoinSignMessage.ts +4 -0
  596. package/src/api/starcoin/StarcoinSignTransaction.ts +4 -0
  597. package/src/api/starcoin/StarcoinVerifyMessage.ts +4 -0
  598. package/src/api/stellar/StellarGetAddress.ts +1 -10
  599. package/src/api/stellar/StellarSignTransaction.ts +1 -14
  600. package/src/api/sui/SuiGetAddress.ts +4 -0
  601. package/src/api/sui/SuiGetPublicKey.ts +4 -0
  602. package/src/api/sui/SuiSignMessage.ts +4 -0
  603. package/src/api/sui/SuiSignTransaction.ts +4 -0
  604. package/src/api/ton/TonGetAddress.ts +4 -0
  605. package/src/api/ton/TonSignData.ts +5 -1
  606. package/src/api/ton/TonSignMessage.ts +4 -0
  607. package/src/api/ton/TonSignProof.ts +4 -0
  608. package/src/api/tron/TronGetAddress.ts +4 -0
  609. package/src/api/tron/TronSignMessage.ts +18 -7
  610. package/src/api/tron/TronSignTransaction.ts +4 -0
  611. package/src/api/utils.ts +7 -3
  612. package/src/api/xrp/XrpGetAddress.ts +4 -0
  613. package/src/api/xrp/XrpSignTransaction.ts +5 -1
  614. package/src/constants/index.ts +1 -4
  615. package/src/core/RequestQueue.ts +1 -0
  616. package/src/core/deviceEventRegistration.ts +27 -0
  617. package/src/core/index.ts +274 -120
  618. package/src/data/messages/messages-protocol-v2.json +1161 -477
  619. package/src/data/messages/messages.json +286 -1
  620. package/src/data-manager/DataManager.ts +6 -6
  621. package/src/data-manager/TransportManager.ts +1 -1
  622. package/src/data-manager/connectSettings.ts +4 -0
  623. package/src/device/Device.ts +820 -282
  624. package/src/device/DeviceCommands.ts +166 -158
  625. package/src/device/DeviceConnector.ts +10 -7
  626. package/src/device/DeviceFeaturesState.ts +25 -0
  627. package/src/device/DevicePool.ts +66 -16
  628. package/src/device/DeviceStateMapper.ts +374 -0
  629. package/src/device/DeviceStateProjector.ts +94 -0
  630. package/src/device/DeviceStateStore.ts +201 -0
  631. package/src/device/DeviceWalletSessionStore.ts +144 -0
  632. package/src/device/cloneDeviceState.ts +39 -0
  633. package/src/device/deviceIdentity.ts +18 -0
  634. package/src/deviceProfile/buildDeviceFeatures.ts +224 -190
  635. package/src/deviceProfile/index.ts +0 -1
  636. package/src/deviceProfile/protocolV2DeviceIdentity.ts +32 -0
  637. package/src/events/device.ts +22 -1
  638. package/src/events/logBlockEvent.ts +80 -2
  639. package/src/events/ui-request.ts +57 -4
  640. package/src/inject.ts +16 -41
  641. package/src/protocols/protocol-v2/deviceSession.ts +24 -0
  642. package/src/protocols/protocol-v2/features.ts +103 -32
  643. package/src/protocols/protocol-v2/firmware.ts +2 -1
  644. package/src/protocols/protocol-v2/index.ts +8 -1
  645. package/src/protocols/protocol-v2/settingsUnlockPolicy.ts +65 -0
  646. package/src/protocols/protocol-v2/uiInteraction.ts +236 -0
  647. package/src/protocols/protocol-v2/unlockPolicy.ts +1 -0
  648. package/src/protocols/protocol-v2/unlockPolicyRunner.ts +117 -0
  649. package/src/protocols/protocol-v2/walletSession.ts +360 -0
  650. package/src/types/api/checkAllFirmwareRelease.ts +46 -4
  651. package/src/types/api/deviceSettings.ts +26 -2
  652. package/src/types/api/deviceUnlock.ts +1 -1
  653. package/src/types/api/export.ts +8 -0
  654. package/src/types/api/firmwareUpdate.ts +23 -5
  655. package/src/types/api/getDeviceState.ts +19 -0
  656. package/src/types/api/getFeatures.ts +3 -0
  657. package/src/types/api/getOnekeyFeatures.ts +3 -0
  658. package/src/types/api/getPassphraseState.ts +9 -11
  659. package/src/types/api/index.ts +27 -64
  660. package/src/types/api/kaspaSignTransaction.ts +60 -4
  661. package/src/types/api/openWalletSession.ts +54 -0
  662. package/src/types/api/protocolV2.ts +33 -139
  663. package/src/types/api/sessionCache.ts +19 -0
  664. package/src/types/device.ts +185 -7
  665. package/src/types/params.ts +3 -2
  666. package/src/types/settings.ts +17 -16
  667. package/src/utils/assets.ts +4 -1
  668. package/src/utils/deviceFeaturesCompat.ts +180 -0
  669. package/src/utils/deviceFeaturesUtils.ts +56 -45
  670. package/src/utils/deviceInfoUtils.ts +27 -69
  671. package/src/utils/deviceSettings.ts +171 -39
  672. package/src/utils/deviceVersionUtils.ts +25 -44
  673. package/src/utils/findDefectiveBatchDevice.ts +3 -3
  674. package/src/utils/homescreen.ts +36 -0
  675. package/src/utils/index.ts +27 -3
  676. package/src/utils/networkUtils.ts +274 -16
  677. package/src/utils/pro2Nft.ts +91 -0
  678. package/src/utils/pro2Wallpaper.ts +130 -0
  679. package/src/utils/tracing.ts +3 -1
  680. package/src/utils/uiProgressThrottle.ts +63 -0
  681. package/tsconfig.type-tests.json +12 -0
  682. package/dist/api/GetDeviceInfo.d.ts +0 -9
  683. package/dist/api/GetDeviceInfo.d.ts.map +0 -1
  684. package/dist/api/protocol-v2/FilesystemDiskControl.d.ts +0 -13
  685. package/dist/api/protocol-v2/FilesystemDiskControl.d.ts.map +0 -1
  686. package/dist/deviceProfile/buildDeviceProfile.d.ts +0 -21
  687. package/dist/deviceProfile/buildDeviceProfile.d.ts.map +0 -1
  688. package/dist/types/api/getDeviceInfo.d.ts +0 -87
  689. package/dist/types/api/getDeviceInfo.d.ts.map +0 -1
  690. package/src/api/GetDeviceInfo.ts +0 -145
  691. package/src/api/protocol-v2/FilesystemDiskControl.ts +0 -50
  692. package/src/deviceProfile/buildDeviceProfile.ts +0 -352
  693. package/src/types/api/getDeviceInfo.ts +0 -101
@@ -0,0 +1,1609 @@
1
+ import { EDeviceType, HardwareErrorCode } from '@onekeyfe/hd-shared';
2
+ import { DeviceSessionPinType } from '@onekeyfe/hd-transport';
3
+
4
+ import GetPassphraseState from '../src/api/GetPassphraseState';
5
+ import OpenWalletSession from '../src/api/OpenWalletSession';
6
+ import { Device } from '../src/device/Device';
7
+ import { deviceWalletSessionStore } from '../src/device/DeviceWalletSessionStore';
8
+ import { ensureProtocolV2WalletSessionUnlocked } from '../src/protocols/protocol-v2/walletSession';
9
+
10
+ jest.mock('../src/data/config', () => ({
11
+ getSDKVersion: jest.fn(() => '1.0.0'),
12
+ DEFAULT_DOMAIN: 'https://jssdk.onekey.so/1.0.0/',
13
+ }));
14
+
15
+ const createDevice = ({
16
+ passphraseProtection = true,
17
+ typedCall = jest.fn(),
18
+ promptPassphrase = jest.fn(),
19
+ }: {
20
+ passphraseProtection?: boolean;
21
+ typedCall?: jest.Mock;
22
+ promptPassphrase?: jest.Mock;
23
+ } = {}) => {
24
+ const device: Record<string, any> = {
25
+ passphraseState: undefined,
26
+ features: {
27
+ unlocked: true,
28
+ passphraseProtection,
29
+ attachToPinEnabled: false,
30
+ unlockedAttachPin: false,
31
+ },
32
+ commands: {
33
+ typedCall: jest.fn((request: string, ...args: unknown[]) => {
34
+ if (request === 'DeviceStatusGet') {
35
+ return {
36
+ message: {
37
+ device_id: 'device-1',
38
+ unlocked: true,
39
+ unlocked_attach_pin: false,
40
+ passphrase_enabled: passphraseProtection,
41
+ },
42
+ };
43
+ }
44
+ return typedCall(request, ...args);
45
+ }),
46
+ promptPassphrase,
47
+ },
48
+ ensureProtocolV2RuntimeContext: jest.fn(() =>
49
+ device.commands.typedCall('ProtocolInfoRequest', 'ProtocolInfo', {
50
+ eventless_wallet_session: true,
51
+ })
52
+ ),
53
+ getDeviceState: jest.fn(() =>
54
+ Promise.resolve({
55
+ identity: { deviceId: 'device-1' },
56
+ status: {
57
+ unlocked: device.features.unlocked,
58
+ passphraseProtection: device.features.passphraseProtection,
59
+ unlockedAttachPin: device.features.unlockedAttachPin,
60
+ },
61
+ })
62
+ ),
63
+ getCurrentDeviceId: () => 'device-1',
64
+ getCurrentPassphraseProtection: () => passphraseProtection,
65
+ getInternalState: () =>
66
+ deviceWalletSessionStore.get('device-1', device.passphraseState as string | undefined),
67
+ updateInternalState: jest.fn(
68
+ (_enabled: boolean, passphraseState: string, deviceId: string, sessionId: string) => {
69
+ deviceWalletSessionStore.set(deviceId, passphraseState, sessionId);
70
+ }
71
+ ),
72
+ clearInternalState: jest.fn(() => {
73
+ if (device.passphraseState) {
74
+ deviceWalletSessionStore.delete('device-1', device.passphraseState);
75
+ }
76
+ }),
77
+ lockDevice: jest.fn(),
78
+ unlockDevice: jest.fn(),
79
+ updateProtocolV2Status: jest.fn((status: Record<string, unknown>) => {
80
+ device.features.unlocked = status.unlocked ?? device.features.unlocked;
81
+ device.features.unlockedAttachPin =
82
+ status.unlocked_attach_pin ?? device.features.unlockedAttachPin;
83
+ return device.features;
84
+ }),
85
+ initialize: jest.fn(),
86
+ emit: jest.fn(),
87
+ isProtocolV2: () => true,
88
+ getCurrentFirmwareType: () => 'universal',
89
+ };
90
+ return device;
91
+ };
92
+
93
+ describe('openWalletSession', () => {
94
+ beforeEach(() => {
95
+ deviceWalletSessionStore.clear();
96
+ });
97
+
98
+ test('unlocks a locked Protocol V2 device before restoring a wallet session', async () => {
99
+ const device = {
100
+ commands: {
101
+ typedCall: jest.fn().mockResolvedValue({ message: { unlocked: false } }),
102
+ },
103
+ isBootloader: jest.fn().mockReturnValue(false),
104
+ isProtocolV2: jest.fn().mockReturnValue(true),
105
+ isRomloader: jest.fn().mockReturnValue(false),
106
+ state: { status: { unlocked: false } },
107
+ unlockDevice: jest.fn().mockResolvedValue(undefined),
108
+ updateProtocolV2Status: jest.fn(function updateProtocolV2Status(
109
+ this: { state: { status: { unlocked: boolean } } },
110
+ status: { unlocked?: boolean }
111
+ ) {
112
+ this.state.status.unlocked = status.unlocked ?? this.state.status.unlocked;
113
+ }),
114
+ };
115
+
116
+ await expect(ensureProtocolV2WalletSessionUnlocked(device as any)).resolves.toBe(true);
117
+ expect(device.commands.typedCall).toHaveBeenCalledWith('DeviceStatusGet', 'DeviceStatus', {});
118
+ expect(device.unlockDevice).toHaveBeenCalledWith(DeviceSessionPinType.Main, {
119
+ source: 'unlock-coordinator',
120
+ reason: 'device-locked',
121
+ deviceOnly: true,
122
+ });
123
+ });
124
+
125
+ test('does not request PIN when wallet-session recovery finds the device unlocked', async () => {
126
+ const device = {
127
+ commands: {
128
+ typedCall: jest.fn().mockResolvedValue({ message: { unlocked: true } }),
129
+ },
130
+ isBootloader: jest.fn().mockReturnValue(false),
131
+ isProtocolV2: jest.fn().mockReturnValue(true),
132
+ isRomloader: jest.fn().mockReturnValue(false),
133
+ state: { status: { unlocked: true } },
134
+ unlockDevice: jest.fn(),
135
+ updateProtocolV2Status: jest.fn(),
136
+ };
137
+
138
+ await expect(ensureProtocolV2WalletSessionUnlocked(device as any)).resolves.toBe(false);
139
+ expect(device.unlockDevice).not.toHaveBeenCalled();
140
+ });
141
+
142
+ test.each([{ useEmptyPassphrase: true }, { initSession: true }, {}])(
143
+ 'requires the explicit mode in the new public API: %p',
144
+ legacyParams => {
145
+ const method = new OpenWalletSession({
146
+ payload: {
147
+ method: 'openWalletSession',
148
+ connectId: 'connect-id',
149
+ ...legacyParams,
150
+ },
151
+ });
152
+
153
+ expect(() => method.init()).toThrow('Parameter [mode] is required');
154
+ }
155
+ );
156
+
157
+ test('keeps the legacy getPassphraseState App flow working on Protocol V2', async () => {
158
+ const typedCall = jest
159
+ .fn()
160
+ .mockResolvedValueOnce({ message: { version: 2 } })
161
+ .mockResolvedValueOnce({ message: {} })
162
+ .mockResolvedValueOnce({
163
+ message: {
164
+ btc_test_address: 'pro2-wallet-state',
165
+ session_id: 'pro2-wallet-session',
166
+ },
167
+ });
168
+ const promptPassphrase = jest.fn().mockResolvedValue({ passphrase: 'host hidden wallet' });
169
+ const method = new GetPassphraseState({
170
+ payload: {
171
+ method: 'getPassphraseState',
172
+ connectId: 'connect-id',
173
+ initSession: true,
174
+ useEmptyPassphrase: false,
175
+ },
176
+ });
177
+ method.device = createDevice({ typedCall, promptPassphrase }) as any;
178
+
179
+ await expect(method.run()).resolves.toBe('pro2-wallet-state');
180
+ expect(promptPassphrase).toHaveBeenCalledWith(
181
+ {
182
+ existsAttachPinUser: false,
183
+ deviceOnly: false,
184
+ source: 'wallet-session-coordinator',
185
+ reason: 'open-wallet',
186
+ },
187
+ { cancelDeviceOnReject: false }
188
+ );
189
+ expect(typedCall).toHaveBeenNthCalledWith(2, 'DeviceSessionAskPassphrase', 'Success', {
190
+ passphrase: 'host hidden wallet',
191
+ on_device: false,
192
+ });
193
+ expect(typedCall).toHaveBeenNthCalledWith(3, 'DeviceSessionGet', 'DeviceSession', {});
194
+ });
195
+
196
+ test('keeps Legacy Protocol V1 getPassphraseState parameterless', async () => {
197
+ const typedCall = jest.fn().mockResolvedValue({
198
+ type: 'PassphraseState',
199
+ message: {
200
+ passphrase_state: 'current-wallet-state',
201
+ session_id: 'current-wallet-session',
202
+ unlocked_attach_pin: false,
203
+ },
204
+ });
205
+ const method = new GetPassphraseState({
206
+ payload: {
207
+ method: 'getPassphraseState',
208
+ connectId: 'connect-id',
209
+ useEmptyPassphrase: true,
210
+ initSession: true,
211
+ passphraseState: 'ignored-wallet-state',
212
+ },
213
+ });
214
+ const device = createDevice({ typedCall });
215
+ device.isProtocolV2 = () => false;
216
+ device.features = {
217
+ ...device.features,
218
+ deviceId: 'device-1',
219
+ passphraseProtection: true,
220
+ unlocked: true,
221
+ sessionId: null,
222
+ };
223
+ device.getCurrentFirmwareVersionString = () => '4.15.0';
224
+ device.getCurrentDeviceType = () => EDeviceType.Pro;
225
+ device.getFeatures = jest.fn();
226
+ method.device = device as any;
227
+
228
+ await expect(method.run()).resolves.toBe('current-wallet-state');
229
+ expect(device.clearInternalState).not.toHaveBeenCalled();
230
+ expect(typedCall).toHaveBeenCalledWith('GetPassphraseState', 'PassphraseState', {
231
+ passphrase_state: undefined,
232
+ });
233
+ });
234
+
235
+ test('opens the standard wallet through the Protocol V1 empty-passphrase flow', async () => {
236
+ const typedCall = jest.fn().mockResolvedValue({
237
+ type: 'PassphraseState',
238
+ message: {
239
+ passphrase_state: 'main-wallet-state',
240
+ session_id: 'main-wallet-session',
241
+ unlocked_attach_pin: false,
242
+ },
243
+ });
244
+ const method = new OpenWalletSession({
245
+ payload: {
246
+ method: 'openWalletSession',
247
+ connectId: 'connect-id',
248
+ mode: 'standard',
249
+ },
250
+ });
251
+ method.init();
252
+ const device = createDevice({ typedCall });
253
+ device.isProtocolV2 = () => false;
254
+ device.features = {
255
+ ...device.features,
256
+ deviceId: 'device-1',
257
+ unlocked: true,
258
+ sessionId: null,
259
+ };
260
+ device.getCurrentFirmwareVersionString = () => '4.15.0';
261
+ device.getCurrentDeviceType = () => EDeviceType.Pro;
262
+ device.getFeatures = jest.fn();
263
+ method.device = device as any;
264
+
265
+ await expect(method.run()).resolves.toEqual({
266
+ protocol: 'V1',
267
+ walletType: 'standard',
268
+ deviceId: 'device-1',
269
+ passphraseState: null,
270
+ resumed: false,
271
+ });
272
+ expect(method.payload.useEmptyPassphrase).toBe(true);
273
+ expect(typedCall).toHaveBeenCalledWith('GetPassphraseState', 'PassphraseState', {
274
+ passphrase_state: undefined,
275
+ });
276
+ expect(device.clearInternalState).not.toHaveBeenCalled();
277
+ });
278
+
279
+ test('uses the explicit mode to select a hidden wallet on Protocol V2', async () => {
280
+ const typedCall = jest
281
+ .fn()
282
+ .mockResolvedValueOnce({ message: { version: 2 } })
283
+ .mockResolvedValueOnce({ message: {} })
284
+ .mockResolvedValueOnce({
285
+ message: {
286
+ btc_test_address: 'hidden-state',
287
+ session_id: 'hidden-session',
288
+ },
289
+ });
290
+ const promptPassphrase = jest.fn().mockResolvedValue({ passphrase: 'host hidden wallet' });
291
+ const method = new OpenWalletSession({
292
+ payload: {
293
+ method: 'openWalletSession',
294
+ connectId: 'connect-id',
295
+ mode: 'select-hidden',
296
+ },
297
+ });
298
+ method.init();
299
+ method.device = createDevice({ typedCall, promptPassphrase }) as any;
300
+
301
+ await expect(method.run()).resolves.toMatchObject({
302
+ protocol: 'V2',
303
+ walletType: 'hidden',
304
+ passphraseState: 'hidden-state',
305
+ });
306
+ expect(promptPassphrase).toHaveBeenCalled();
307
+ expect(typedCall).toHaveBeenNthCalledWith(2, 'DeviceSessionAskPassphrase', 'Success', {
308
+ passphrase: 'host hidden wallet',
309
+ on_device: false,
310
+ });
311
+ expect(typedCall).toHaveBeenNthCalledWith(3, 'DeviceSessionGet', 'DeviceSession', {});
312
+ });
313
+
314
+ test('refreshes Pro2 status and unlocks before selecting a hidden wallet when locked', async () => {
315
+ const typedCall = jest
316
+ .fn()
317
+ .mockResolvedValueOnce({ message: { version: 2 } })
318
+ .mockResolvedValueOnce({ message: {} })
319
+ .mockResolvedValueOnce({
320
+ message: {
321
+ btc_test_address: 'hidden-state-after-preflight',
322
+ session_id: 'hidden-session-after-preflight',
323
+ },
324
+ });
325
+ const method = new OpenWalletSession({
326
+ payload: { method: 'openWalletSession', connectId: 'connect-id', mode: 'select-hidden' },
327
+ });
328
+ method.init();
329
+ const device = createDevice({
330
+ typedCall,
331
+ promptPassphrase: jest.fn().mockResolvedValue({ passphraseOnDevice: true }),
332
+ });
333
+ device.getDeviceState = jest
334
+ .fn()
335
+ .mockResolvedValueOnce({
336
+ identity: { deviceId: 'device-1' },
337
+ status: {
338
+ unlocked: false,
339
+ passphraseProtection: null,
340
+ unlockedAttachPin: null,
341
+ },
342
+ })
343
+ .mockResolvedValue({
344
+ identity: { deviceId: 'device-1' },
345
+ status: {
346
+ unlocked: true,
347
+ passphraseProtection: true,
348
+ unlockedAttachPin: false,
349
+ },
350
+ });
351
+ method.device = device as any;
352
+
353
+ await expect(method.run()).resolves.toMatchObject({
354
+ walletType: 'hidden',
355
+ passphraseState: 'hidden-state-after-preflight',
356
+ });
357
+ expect(device.unlockDevice).toHaveBeenCalledTimes(1);
358
+ expect(device.unlockDevice.mock.invocationCallOrder[0]).toBeLessThan(
359
+ typedCall.mock.invocationCallOrder[0]
360
+ );
361
+ });
362
+
363
+ test('classifies the selected Pro2 wallet from the post-unlock device state', async () => {
364
+ const typedCall = jest
365
+ .fn()
366
+ .mockResolvedValueOnce({ message: { version: 2 } })
367
+ .mockResolvedValueOnce({ message: {} })
368
+ .mockResolvedValueOnce({
369
+ message: {
370
+ btc_test_address: 'hidden-state-after-unlock',
371
+ session_id: 'hidden-session-after-unlock',
372
+ },
373
+ });
374
+ const promptPassphrase = jest.fn().mockResolvedValue({ passphrase: 'host hidden wallet' });
375
+ const method = new OpenWalletSession({
376
+ payload: { method: 'openWalletSession', connectId: 'connect-id', mode: 'select-hidden' },
377
+ });
378
+ method.init();
379
+ const device = createDevice({
380
+ passphraseProtection: false,
381
+ typedCall,
382
+ promptPassphrase,
383
+ });
384
+ device.features.unlocked = false;
385
+ device.getCurrentPassphraseProtection = () => device.features.passphraseProtection;
386
+ device.commands.typedCall = jest.fn((request: string, ...args: unknown[]) => {
387
+ if (request === 'DeviceStatusGet') {
388
+ return {
389
+ message: {
390
+ device_id: 'device-1',
391
+ unlocked: true,
392
+ passphrase_enabled: true,
393
+ },
394
+ };
395
+ }
396
+ return typedCall(request, ...args);
397
+ });
398
+ device.updateProtocolV2Status = jest.fn((status: Record<string, unknown>) => {
399
+ device.features.unlocked = status.unlocked ?? device.features.unlocked;
400
+ device.features.passphraseProtection =
401
+ status.passphrase_enabled ?? device.features.passphraseProtection;
402
+ return device.features;
403
+ });
404
+ device.unlockDevice = jest.fn().mockImplementation(() => {
405
+ device.features.unlocked = true;
406
+ device.features.passphraseProtection = true;
407
+ device.features.unlockedAttachPin = false;
408
+ return Promise.resolve(device.features);
409
+ });
410
+ method.device = device as any;
411
+
412
+ await expect(method.run()).resolves.toEqual({
413
+ protocol: 'V2',
414
+ walletType: 'hidden',
415
+ deviceId: 'device-1',
416
+ passphraseState: 'hidden-state-after-unlock',
417
+ resumed: false,
418
+ });
419
+ expect(device.unlockDevice).toHaveBeenCalledTimes(1);
420
+ expect(promptPassphrase).toHaveBeenCalledTimes(1);
421
+ });
422
+
423
+ test('unlocks before wallet selection when the Protocol V2 wallet status is unknown', async () => {
424
+ const typedCall = jest
425
+ .fn()
426
+ .mockResolvedValueOnce({ message: { version: 2 } })
427
+ .mockResolvedValueOnce({ message: {} })
428
+ .mockResolvedValueOnce({
429
+ message: {
430
+ btc_test_address: 'hidden-state-after-unknown-status',
431
+ session_id: 'hidden-session-after-unknown-status',
432
+ },
433
+ });
434
+ const promptPassphrase = jest.fn().mockResolvedValue({ passphrase: 'host hidden wallet' });
435
+ const method = new OpenWalletSession({
436
+ payload: { method: 'openWalletSession', connectId: 'connect-id', mode: 'select-hidden' },
437
+ });
438
+ method.init();
439
+ const device = createDevice({ typedCall, promptPassphrase });
440
+ device.getDeviceState = jest
441
+ .fn()
442
+ .mockResolvedValueOnce({
443
+ identity: { deviceId: 'device-1' },
444
+ status: {
445
+ unlocked: undefined,
446
+ passphraseProtection: null,
447
+ unlockedAttachPin: null,
448
+ },
449
+ })
450
+ .mockResolvedValue({
451
+ identity: { deviceId: 'device-1' },
452
+ status: {
453
+ unlocked: true,
454
+ passphraseProtection: true,
455
+ unlockedAttachPin: false,
456
+ },
457
+ });
458
+ device.unlockDevice = jest.fn().mockImplementation(() => {
459
+ device.features.unlocked = true;
460
+ device.features.passphraseProtection = true;
461
+ device.features.unlockedAttachPin = false;
462
+ return Promise.resolve(device.features);
463
+ });
464
+ method.device = device as any;
465
+
466
+ await expect(method.run()).resolves.toMatchObject({
467
+ walletType: 'hidden',
468
+ passphraseState: 'hidden-state-after-unknown-status',
469
+ });
470
+ expect(device.unlockDevice).toHaveBeenCalledTimes(1);
471
+ expect(device.unlockDevice.mock.invocationCallOrder[0]).toBeLessThan(
472
+ promptPassphrase.mock.invocationCallOrder[0]
473
+ );
474
+ });
475
+
476
+ test('rejects wallet selection when the post-unlock Protocol V2 status remains incomplete', async () => {
477
+ const typedCall = jest
478
+ .fn()
479
+ .mockResolvedValueOnce({ message: { version: 2 } })
480
+ .mockResolvedValueOnce({ message: {} })
481
+ .mockResolvedValueOnce({
482
+ message: {
483
+ btc_test_address: 'hidden-state-from-incomplete-status',
484
+ session_id: 'hidden-session-from-incomplete-status',
485
+ },
486
+ });
487
+ const promptPassphrase = jest.fn().mockResolvedValue({ passphrase: 'host hidden wallet' });
488
+ const method = new OpenWalletSession({
489
+ payload: { method: 'openWalletSession', connectId: 'connect-id', mode: 'select-hidden' },
490
+ });
491
+ method.init();
492
+ const device = createDevice({ typedCall, promptPassphrase });
493
+ device.getDeviceState = jest.fn().mockResolvedValue({
494
+ identity: { deviceId: 'device-1' },
495
+ status: {
496
+ unlocked: true,
497
+ passphraseProtection: null,
498
+ unlockedAttachPin: null,
499
+ },
500
+ });
501
+ device.unlockDevice = jest.fn().mockResolvedValue(device.features);
502
+ method.device = device as any;
503
+
504
+ await expect(method.run()).rejects.toMatchObject({
505
+ errorCode: HardwareErrorCode.DeviceInitializeFailed,
506
+ });
507
+ expect(device.unlockDevice).toHaveBeenCalledTimes(1);
508
+ expect(promptPassphrase).not.toHaveBeenCalled();
509
+ });
510
+
511
+ test('rejects a Pro2 standard-wallet fallback after selecting a hidden wallet', async () => {
512
+ const typedCall = jest
513
+ .fn()
514
+ .mockResolvedValueOnce({ message: { version: 2 } })
515
+ .mockResolvedValueOnce({ message: {} })
516
+ .mockResolvedValueOnce({
517
+ message: {
518
+ btc_test_address: 'standard-wallet-state',
519
+ session_id: 'standard-wallet-session',
520
+ },
521
+ });
522
+ const promptPassphrase = jest.fn().mockResolvedValue({ passphraseOnDevice: true });
523
+ const method = new OpenWalletSession({
524
+ payload: { method: 'openWalletSession', connectId: 'connect-id', mode: 'select-hidden' },
525
+ });
526
+ method.init();
527
+ const device = createDevice({
528
+ passphraseProtection: false,
529
+ typedCall,
530
+ promptPassphrase,
531
+ });
532
+ method.device = device as any;
533
+
534
+ await expect(method.run()).rejects.toMatchObject({
535
+ errorCode: HardwareErrorCode.DeviceNotOpenedPassphrase,
536
+ });
537
+ expect(device.clearInternalState).toHaveBeenCalled();
538
+ });
539
+
540
+ test('select-hidden starts a fresh hidden-wallet session on Protocol V2', async () => {
541
+ const typedCall = jest
542
+ .fn()
543
+ .mockResolvedValueOnce({ message: { version: 2 } })
544
+ .mockResolvedValueOnce({ message: {} })
545
+ .mockResolvedValueOnce({
546
+ message: {
547
+ btc_test_address: 'new-hidden-state',
548
+ session_id: 'new-hidden-session',
549
+ },
550
+ });
551
+ const promptPassphrase = jest.fn().mockResolvedValue({ passphrase: 'host hidden wallet' });
552
+ const method = new OpenWalletSession({
553
+ payload: {
554
+ method: 'openWalletSession',
555
+ connectId: 'connect-id',
556
+ mode: 'select-hidden',
557
+ },
558
+ });
559
+ method.init();
560
+ method.device = createDevice({ typedCall, promptPassphrase }) as any;
561
+
562
+ await expect(method.run()).resolves.toEqual({
563
+ protocol: 'V2',
564
+ walletType: 'hidden',
565
+ deviceId: 'device-1',
566
+ passphraseState: 'new-hidden-state',
567
+ resumed: false,
568
+ });
569
+ expect(typedCall).toHaveBeenCalledWith('ProtocolInfoRequest', 'ProtocolInfo', {
570
+ eventless_wallet_session: true,
571
+ });
572
+ expect(typedCall).toHaveBeenCalledWith('DeviceSessionAskPassphrase', 'Success', {
573
+ passphrase: 'host hidden wallet',
574
+ on_device: false,
575
+ });
576
+ expect(typedCall).toHaveBeenCalledWith('DeviceSessionGet', 'DeviceSession', {});
577
+ expect(promptPassphrase).toHaveBeenCalled();
578
+ expect(deviceWalletSessionStore.get('device-1', 'new-hidden-state')).toBe('new-hidden-session');
579
+ });
580
+
581
+ test('select-hidden does not clear another device wallet', async () => {
582
+ const typedCall = jest
583
+ .fn()
584
+ .mockResolvedValueOnce({ message: { version: 2 } })
585
+ .mockResolvedValueOnce({ message: {} })
586
+ .mockResolvedValueOnce({
587
+ message: {
588
+ btc_test_address: 'current-device-state',
589
+ session_id: 'current-device-session',
590
+ },
591
+ });
592
+ const promptPassphrase = jest.fn().mockResolvedValue({ passphrase: 'host hidden wallet' });
593
+ const method = new OpenWalletSession({
594
+ payload: {
595
+ method: 'openWalletSession',
596
+ connectId: 'connect-id',
597
+ mode: 'select-hidden',
598
+ },
599
+ });
600
+ method.init();
601
+ deviceWalletSessionStore.set('other-device', 'other-device-state', 'other-device-session');
602
+ method.device = createDevice({ typedCall, promptPassphrase }) as any;
603
+
604
+ await expect(method.run()).resolves.toMatchObject({
605
+ deviceId: 'device-1',
606
+ passphraseState: 'current-device-state',
607
+ resumed: false,
608
+ });
609
+ expect(deviceWalletSessionStore.get('other-device', 'other-device-state')).toBe(
610
+ 'other-device-session'
611
+ );
612
+ });
613
+
614
+ test('uses an explicit wallet binding to resume on Protocol V2', async () => {
615
+ const typedCall = jest
616
+ .fn()
617
+ .mockResolvedValueOnce({ message: { version: 2 } })
618
+ .mockResolvedValueOnce({
619
+ message: {
620
+ btc_test_address: 'hidden-state',
621
+ session_id: 'renewed-session',
622
+ },
623
+ });
624
+ const promptPassphrase = jest.fn();
625
+ const method = new OpenWalletSession({
626
+ payload: {
627
+ method: 'openWalletSession',
628
+ connectId: 'connect-id',
629
+ mode: 'resume-hidden',
630
+ deviceId: 'device-1',
631
+ passphraseState: 'hidden-state',
632
+ },
633
+ });
634
+ method.init();
635
+ deviceWalletSessionStore.set('device-1', 'hidden-state', 'known-session');
636
+ method.device = createDevice({ typedCall, promptPassphrase }) as any;
637
+
638
+ await expect(method.run()).resolves.toEqual({
639
+ protocol: 'V2',
640
+ walletType: 'hidden',
641
+ deviceId: 'device-1',
642
+ passphraseState: 'hidden-state',
643
+ resumed: true,
644
+ });
645
+ expect(typedCall).toHaveBeenCalledWith('DeviceSessionGet', 'DeviceSession', {
646
+ session_id: 'known-session',
647
+ });
648
+ expect(promptPassphrase).not.toHaveBeenCalled();
649
+ });
650
+
651
+ test.each([
652
+ {
653
+ mode: 'standard',
654
+ initSession: true,
655
+ },
656
+ {
657
+ mode: 'select-hidden',
658
+ useEmptyPassphrase: false,
659
+ },
660
+ {
661
+ mode: 'select-hidden',
662
+ deviceId: 'device-1',
663
+ passphraseState: 'hidden-state',
664
+ },
665
+ {
666
+ mode: 'resume-hidden',
667
+ deviceId: 'device-1',
668
+ passphraseState: 'hidden-state',
669
+ initSession: false,
670
+ },
671
+ ])('rejects legacy parameters combined with explicit mode: %o', params => {
672
+ const method = new OpenWalletSession({
673
+ payload: {
674
+ method: 'openWalletSession',
675
+ connectId: 'connect-id',
676
+ ...params,
677
+ } as any,
678
+ });
679
+
680
+ expect(() => method.init()).toThrow(
681
+ expect.objectContaining({
682
+ errorCode: HardwareErrorCode.CallMethodInvalidParameter,
683
+ })
684
+ );
685
+ });
686
+
687
+ test.each([{ initSession: 'true' }, { useEmptyPassphrase: 'false' }])(
688
+ 'rejects legacy flags without an explicit mode: %o',
689
+ params => {
690
+ const method = new OpenWalletSession({
691
+ payload: {
692
+ method: 'openWalletSession',
693
+ connectId: 'connect-id',
694
+ ...params,
695
+ } as any,
696
+ });
697
+
698
+ expect(() => method.init()).toThrow(
699
+ expect.objectContaining({
700
+ errorCode: HardwareErrorCode.CallMethodInvalidParameter,
701
+ })
702
+ );
703
+ }
704
+ );
705
+
706
+ test('reuses the SDK-managed Protocol V1 hidden-wallet session before validation', async () => {
707
+ const typedCall = jest.fn().mockResolvedValue({
708
+ type: 'PassphraseState',
709
+ message: {
710
+ passphrase_state: 'hidden-state',
711
+ session_id: 'known-session',
712
+ unlocked_attach_pin: false,
713
+ },
714
+ });
715
+ const method = new OpenWalletSession({
716
+ payload: {
717
+ method: 'openWalletSession',
718
+ connectId: 'connect-id',
719
+ mode: 'resume-hidden',
720
+ deviceId: 'device-1',
721
+ passphraseState: 'hidden-state',
722
+ },
723
+ });
724
+ method.init();
725
+ deviceWalletSessionStore.set('device-1', 'hidden-state', 'known-session');
726
+ const device = createDevice({ typedCall });
727
+ device.isProtocolV2 = () => false;
728
+ device.features = {
729
+ ...device.features,
730
+ deviceId: 'device-1',
731
+ unlocked: true,
732
+ sessionId: null,
733
+ };
734
+ device.getCurrentFirmwareVersionString = () => '4.15.0';
735
+ device.getCurrentDeviceType = () => EDeviceType.Pro;
736
+ device.getFeatures = jest.fn();
737
+ method.device = device as any;
738
+
739
+ await expect(method.run()).resolves.toMatchObject({
740
+ protocol: 'V1',
741
+ walletType: 'hidden',
742
+ passphraseState: 'hidden-state',
743
+ resumed: true,
744
+ });
745
+ expect(device.initialize).toHaveBeenCalledWith({
746
+ deviceId: 'device-1',
747
+ passphraseState: 'hidden-state',
748
+ });
749
+ expect(typedCall).toHaveBeenCalledWith('GetPassphraseState', 'PassphraseState', {
750
+ passphrase_state: 'hidden-state',
751
+ });
752
+ });
753
+
754
+ test('rejects a Protocol V1 resume when the device returns another hidden wallet', async () => {
755
+ const typedCall = jest.fn().mockResolvedValue({
756
+ type: 'PassphraseState',
757
+ message: {
758
+ passphrase_state: 'other-hidden-state',
759
+ session_id: 'other-session',
760
+ unlocked_attach_pin: false,
761
+ },
762
+ });
763
+ const method = new OpenWalletSession({
764
+ payload: {
765
+ method: 'openWalletSession',
766
+ connectId: 'connect-id',
767
+ mode: 'resume-hidden',
768
+ deviceId: 'device-1',
769
+ passphraseState: 'hidden-state',
770
+ },
771
+ });
772
+ method.init();
773
+ deviceWalletSessionStore.set('device-1', 'hidden-state', 'known-session');
774
+ const device = createDevice({ typedCall });
775
+ device.isProtocolV2 = () => false;
776
+ device.features = {
777
+ ...device.features,
778
+ deviceId: 'device-1',
779
+ unlocked: true,
780
+ sessionId: null,
781
+ };
782
+ device.getCurrentFirmwareVersionString = () => '4.15.0';
783
+ device.getCurrentDeviceType = () => EDeviceType.Pro;
784
+ device.getFeatures = jest.fn();
785
+ method.device = device as any;
786
+
787
+ await expect(method.run()).rejects.toMatchObject({
788
+ errorCode: HardwareErrorCode.DeviceCheckPassphraseStateError,
789
+ });
790
+ expect(device.clearInternalState).toHaveBeenCalledTimes(1);
791
+ expect(deviceWalletSessionStore.get('device-1', 'hidden-state')).toBeUndefined();
792
+ });
793
+
794
+ test('opens the standard wallet without selecting a hidden wallet', async () => {
795
+ const typedCall = jest
796
+ .fn()
797
+ .mockResolvedValueOnce({ message: { version: 2 } })
798
+ .mockResolvedValueOnce({
799
+ message: {
800
+ btc_test_address: 'main-wallet-state',
801
+ session_id: 'main-wallet-session',
802
+ },
803
+ });
804
+ const promptPassphrase = jest.fn();
805
+ const method = new OpenWalletSession({
806
+ payload: { method: 'openWalletSession', connectId: 'connect-id', mode: 'standard' },
807
+ });
808
+ method.init();
809
+ const device = createDevice({ typedCall, promptPassphrase });
810
+ device.passphraseState = 'previous-hidden-state';
811
+ method.device = device as any;
812
+
813
+ await expect(method.run()).resolves.toEqual({
814
+ protocol: 'V2',
815
+ walletType: 'standard',
816
+ deviceId: 'device-1',
817
+ passphraseState: null,
818
+ resumed: false,
819
+ });
820
+ expect(typedCall).toHaveBeenCalledTimes(2);
821
+ expect(typedCall).toHaveBeenCalledWith('ProtocolInfoRequest', 'ProtocolInfo', {
822
+ eventless_wallet_session: true,
823
+ });
824
+ expect(device.unlockDevice).toHaveBeenCalledWith(DeviceSessionPinType.Main, {
825
+ source: 'wallet-session-coordinator',
826
+ reason: 'open-wallet',
827
+ deviceOnly: true,
828
+ });
829
+ expect(typedCall).toHaveBeenCalledWith('DeviceSessionGet', 'DeviceSession', {});
830
+ expect(promptPassphrase).not.toHaveBeenCalled();
831
+ expect(device.passphraseState).toBeUndefined();
832
+ });
833
+
834
+ test('opens a locked Protocol V2 standard wallet after deviceId becomes available', async () => {
835
+ const typedCall = jest
836
+ .fn()
837
+ .mockResolvedValueOnce({ message: { version: 2 } })
838
+ .mockResolvedValueOnce({
839
+ message: {
840
+ btc_test_address: 'main-wallet-state',
841
+ session_id: 'main-wallet-session',
842
+ },
843
+ });
844
+ const method = new OpenWalletSession({
845
+ payload: { method: 'openWalletSession', connectId: 'connect-id', mode: 'standard' },
846
+ });
847
+ method.init();
848
+ const device = createDevice({ typedCall });
849
+ device.features.unlocked = false;
850
+ device.getDeviceState = jest
851
+ .fn()
852
+ .mockResolvedValueOnce({
853
+ identity: { deviceId: undefined },
854
+ status: { unlocked: false, passphraseProtection: true },
855
+ })
856
+ .mockResolvedValueOnce({
857
+ identity: { deviceId: 'device-1' },
858
+ status: {
859
+ unlocked: true,
860
+ passphraseProtection: true,
861
+ unlockedAttachPin: false,
862
+ },
863
+ });
864
+ device.unlockDevice = jest.fn().mockImplementation(() => {
865
+ device.features.unlocked = true;
866
+ return Promise.resolve(device.features);
867
+ });
868
+ method.device = device as any;
869
+
870
+ await expect(method.run()).resolves.toEqual({
871
+ protocol: 'V2',
872
+ walletType: 'standard',
873
+ deviceId: 'device-1',
874
+ passphraseState: null,
875
+ resumed: false,
876
+ });
877
+ expect(device.unlockDevice).toHaveBeenCalledWith(DeviceSessionPinType.Main, {
878
+ source: 'wallet-session-coordinator',
879
+ reason: 'open-wallet',
880
+ deviceOnly: true,
881
+ });
882
+ expect(device.getDeviceState).toHaveBeenCalledTimes(2);
883
+ });
884
+
885
+ test('switches from Attach PIN to Main PIN before opening the standard wallet', async () => {
886
+ const typedCall = jest
887
+ .fn()
888
+ .mockResolvedValueOnce({ message: { version: 2 } })
889
+ .mockResolvedValueOnce({
890
+ message: {
891
+ btc_test_address: 'main-wallet-state',
892
+ session_id: 'main-wallet-session',
893
+ },
894
+ });
895
+ const method = new OpenWalletSession({
896
+ payload: { method: 'openWalletSession', connectId: 'connect-id', mode: 'standard' },
897
+ });
898
+ method.init();
899
+ const device = createDevice({ typedCall });
900
+ device.features.unlockedAttachPin = true;
901
+ device.getDeviceState = jest
902
+ .fn()
903
+ .mockResolvedValueOnce({
904
+ identity: { deviceId: 'device-1' },
905
+ status: {
906
+ unlocked: true,
907
+ unlockedAttachPin: true,
908
+ passphraseProtection: true,
909
+ },
910
+ })
911
+ .mockResolvedValue({
912
+ identity: { deviceId: 'device-1' },
913
+ status: {
914
+ unlocked: true,
915
+ unlockedAttachPin: false,
916
+ passphraseProtection: true,
917
+ },
918
+ });
919
+ device.unlockDevice = jest.fn().mockImplementation(() => {
920
+ device.features.unlockedAttachPin = false;
921
+ return Promise.resolve(device.features);
922
+ });
923
+ method.device = device as any;
924
+
925
+ await expect(method.run()).resolves.toMatchObject({
926
+ walletType: 'standard',
927
+ passphraseState: null,
928
+ });
929
+ expect(device.unlockDevice).toHaveBeenCalledWith(DeviceSessionPinType.Main, {
930
+ source: 'wallet-session-coordinator',
931
+ reason: 'open-wallet',
932
+ deviceOnly: true,
933
+ });
934
+ expect(typedCall).toHaveBeenCalledWith('DeviceSessionGet', 'DeviceSession', {});
935
+ });
936
+
937
+ test('selects a hidden wallet without exposing the internal device session', async () => {
938
+ const typedCall = jest
939
+ .fn()
940
+ .mockResolvedValueOnce({ message: { version: 2 } })
941
+ .mockResolvedValueOnce({ message: {} })
942
+ .mockResolvedValueOnce({
943
+ message: {
944
+ btc_test_address: 'hidden-state',
945
+ session_id: 'hidden-session',
946
+ },
947
+ });
948
+ const promptPassphrase = jest.fn().mockResolvedValue({ passphrase: 'host hidden wallet' });
949
+ const method = new OpenWalletSession({
950
+ payload: { method: 'openWalletSession', connectId: 'connect-id', mode: 'select-hidden' },
951
+ });
952
+ method.init();
953
+ const device = createDevice({ typedCall, promptPassphrase });
954
+ device.passphraseState = 'previous-hidden-state';
955
+ method.device = device as any;
956
+
957
+ await expect(method.run()).resolves.toEqual({
958
+ protocol: 'V2',
959
+ walletType: 'hidden',
960
+ deviceId: 'device-1',
961
+ passphraseState: 'hidden-state',
962
+ resumed: false,
963
+ });
964
+ expect(typedCall).toHaveBeenCalledWith('DeviceSessionAskPassphrase', 'Success', {
965
+ passphrase: 'host hidden wallet',
966
+ on_device: false,
967
+ });
968
+ expect(typedCall).toHaveBeenCalledWith('DeviceSessionGet', 'DeviceSession', {});
969
+ expect(promptPassphrase).toHaveBeenCalled();
970
+ expect(device.passphraseState).toBeUndefined();
971
+ expect(deviceWalletSessionStore.get('device-1', 'hidden-state')).toBe('hidden-session');
972
+ });
973
+
974
+ test('gets the prepared session after host passphrase entry', async () => {
975
+ const typedCall = jest
976
+ .fn()
977
+ .mockResolvedValueOnce({ message: { version: 2 } })
978
+ .mockResolvedValueOnce({ message: {} })
979
+ .mockResolvedValueOnce({
980
+ message: { btc_test_address: 'device-state', session_id: 'device-session' },
981
+ });
982
+ const promptPassphrase = jest.fn().mockResolvedValue({ passphrase: 'host hidden wallet' });
983
+ const method = new OpenWalletSession({
984
+ payload: { method: 'openWalletSession', connectId: 'connect-id', mode: 'select-hidden' },
985
+ });
986
+ method.init();
987
+ method.device = createDevice({ typedCall, promptPassphrase }) as any;
988
+
989
+ await expect(method.run()).resolves.toMatchObject({
990
+ walletType: 'hidden',
991
+ passphraseState: 'device-state',
992
+ });
993
+ expect(typedCall).toHaveBeenCalledWith('DeviceSessionAskPassphrase', 'Success', {
994
+ passphrase: 'host hidden wallet',
995
+ on_device: false,
996
+ });
997
+ expect(typedCall).toHaveBeenCalledWith('DeviceSessionGet', 'DeviceSession', {});
998
+ });
999
+
1000
+ test('selects an on-device passphrase wallet with an explicit on_device request', async () => {
1001
+ const typedCall = jest
1002
+ .fn()
1003
+ .mockResolvedValueOnce({ message: { version: 2 } })
1004
+ .mockResolvedValueOnce({ message: {} })
1005
+ .mockResolvedValueOnce({
1006
+ message: { btc_test_address: 'device-state', session_id: 'device-session' },
1007
+ });
1008
+ const promptPassphrase = jest.fn().mockResolvedValue({ passphraseOnDevice: true });
1009
+ const method = new OpenWalletSession({
1010
+ payload: { method: 'openWalletSession', connectId: 'connect-id', mode: 'select-hidden' },
1011
+ });
1012
+ method.init();
1013
+ method.device = createDevice({ typedCall, promptPassphrase }) as any;
1014
+
1015
+ await expect(method.run()).resolves.toMatchObject({
1016
+ walletType: 'hidden',
1017
+ passphraseState: 'device-state',
1018
+ });
1019
+ expect(typedCall).toHaveBeenNthCalledWith(2, 'DeviceSessionAskPassphrase', 'Success', {
1020
+ on_device: true,
1021
+ });
1022
+ expect(typedCall).toHaveBeenNthCalledWith(3, 'DeviceSessionGet', 'DeviceSession', {});
1023
+ });
1024
+
1025
+ test('forwards a host passphrase to Pro2 firmware', async () => {
1026
+ const typedCall = jest
1027
+ .fn()
1028
+ .mockResolvedValueOnce({ message: { version: 2 } })
1029
+ .mockResolvedValueOnce({ message: {} })
1030
+ .mockResolvedValueOnce({
1031
+ message: { btc_test_address: 'host-state', session_id: 'host-session' },
1032
+ });
1033
+ const promptPassphrase = jest.fn().mockResolvedValue({ passphrase: 'host hidden wallet' });
1034
+ const method = new OpenWalletSession({
1035
+ payload: {
1036
+ method: 'openWalletSession',
1037
+ connectId: 'connect-id',
1038
+ mode: 'select-hidden',
1039
+ },
1040
+ });
1041
+ method.init();
1042
+ method.device = createDevice({
1043
+ typedCall,
1044
+ promptPassphrase,
1045
+ }) as any;
1046
+
1047
+ await expect(method.run()).resolves.toMatchObject({
1048
+ walletType: 'hidden',
1049
+ passphraseState: 'host-state',
1050
+ });
1051
+ expect(promptPassphrase).toHaveBeenCalledWith(
1052
+ {
1053
+ existsAttachPinUser: false,
1054
+ deviceOnly: false,
1055
+ source: 'wallet-session-coordinator',
1056
+ reason: 'open-wallet',
1057
+ },
1058
+ { cancelDeviceOnReject: false }
1059
+ );
1060
+ expect(typedCall).toHaveBeenNthCalledWith(2, 'DeviceSessionAskPassphrase', 'Success', {
1061
+ passphrase: 'host hidden wallet',
1062
+ on_device: false,
1063
+ });
1064
+ expect(typedCall).toHaveBeenNthCalledWith(3, 'DeviceSessionGet', 'DeviceSession', {});
1065
+ });
1066
+
1067
+ test('normalizes a Unicode Host passphrase before sending it to Pro2 firmware', async () => {
1068
+ const typedCall = jest
1069
+ .fn()
1070
+ .mockResolvedValueOnce({ message: { version: 2 } })
1071
+ .mockResolvedValueOnce({ message: {} })
1072
+ .mockResolvedValueOnce({
1073
+ message: { btc_test_address: 'host-state', session_id: 'host-session' },
1074
+ });
1075
+ const promptPassphrase = jest.fn().mockResolvedValue({ passphrase: 'caf\u00e9' });
1076
+ const method = new OpenWalletSession({
1077
+ payload: { method: 'openWalletSession', connectId: 'connect-id', mode: 'select-hidden' },
1078
+ });
1079
+ method.init();
1080
+ method.device = createDevice({ typedCall, promptPassphrase }) as any;
1081
+
1082
+ await expect(method.run()).resolves.toMatchObject({ passphraseState: 'host-state' });
1083
+ expect(typedCall).toHaveBeenNthCalledWith(2, 'DeviceSessionAskPassphrase', 'Success', {
1084
+ passphrase: 'cafe\u0301',
1085
+ on_device: false,
1086
+ });
1087
+ });
1088
+
1089
+ test('accepts a Host passphrase at the 50-byte firmware boundary', async () => {
1090
+ const passphrase = 'a'.repeat(50);
1091
+ const typedCall = jest
1092
+ .fn()
1093
+ .mockResolvedValueOnce({ message: { version: 2 } })
1094
+ .mockResolvedValueOnce({ message: {} })
1095
+ .mockResolvedValueOnce({
1096
+ message: { btc_test_address: 'host-state', session_id: 'host-session' },
1097
+ });
1098
+ const promptPassphrase = jest.fn().mockResolvedValue({ passphrase });
1099
+ const method = new OpenWalletSession({
1100
+ payload: { method: 'openWalletSession', connectId: 'connect-id', mode: 'select-hidden' },
1101
+ });
1102
+ method.init();
1103
+ method.device = createDevice({ typedCall, promptPassphrase }) as any;
1104
+
1105
+ await expect(method.run()).resolves.toMatchObject({ passphraseState: 'host-state' });
1106
+ expect(typedCall).toHaveBeenNthCalledWith(2, 'DeviceSessionAskPassphrase', 'Success', {
1107
+ passphrase,
1108
+ on_device: false,
1109
+ });
1110
+ });
1111
+
1112
+ test('selects Attach PIN only when the device reports an existing binding', async () => {
1113
+ const typedCall = jest
1114
+ .fn()
1115
+ .mockResolvedValueOnce({ message: { version: 2 } })
1116
+ .mockResolvedValueOnce({
1117
+ message: { btc_test_address: 'attach-state', session_id: 'attach-session' },
1118
+ });
1119
+ const promptPassphrase = jest.fn().mockResolvedValue({ attachPinOnDevice: true });
1120
+ const method = new OpenWalletSession({
1121
+ payload: { method: 'openWalletSession', connectId: 'connect-id', mode: 'select-hidden' },
1122
+ });
1123
+ method.init();
1124
+ const device = createDevice({ typedCall, promptPassphrase });
1125
+ device.features.attachToPinEnabled = true;
1126
+ method.device = device as any;
1127
+
1128
+ await expect(method.run()).resolves.toMatchObject({
1129
+ walletType: 'hidden',
1130
+ passphraseState: 'attach-state',
1131
+ });
1132
+ expect(promptPassphrase).toHaveBeenCalledWith(
1133
+ {
1134
+ existsAttachPinUser: true,
1135
+ deviceOnly: false,
1136
+ source: 'wallet-session-coordinator',
1137
+ reason: 'open-wallet',
1138
+ },
1139
+ { cancelDeviceOnReject: false }
1140
+ );
1141
+ expect(device.unlockDevice).toHaveBeenCalledWith(DeviceSessionPinType.AttachToPin, {
1142
+ emitUiEvent: false,
1143
+ });
1144
+ expect(typedCall).toHaveBeenCalledWith('DeviceSessionGet', 'DeviceSession', {});
1145
+ });
1146
+
1147
+ test('uses the complete Attach PIN wire flow without a main PIN unlock', async () => {
1148
+ const typedCall = jest
1149
+ .fn()
1150
+ .mockResolvedValueOnce({ message: { version: 2 } })
1151
+ .mockResolvedValueOnce({ message: { message: 'PIN verified' } })
1152
+ .mockResolvedValueOnce({
1153
+ message: { btc_test_address: 'attach-state', session_id: 'attach-session' },
1154
+ });
1155
+ const promptPassphrase = jest.fn().mockResolvedValue({ attachPinOnDevice: true });
1156
+ const method = new OpenWalletSession({
1157
+ payload: { method: 'openWalletSession', connectId: 'connect-id', mode: 'select-hidden' },
1158
+ });
1159
+ method.init();
1160
+ const device = createDevice({ typedCall, promptPassphrase });
1161
+ device.features.attachToPinEnabled = true;
1162
+ device.unlockDevice = Device.prototype.unlockDevice.bind(device);
1163
+ method.device = device as any;
1164
+
1165
+ await expect(method.run()).resolves.toMatchObject({
1166
+ walletType: 'hidden',
1167
+ passphraseState: 'attach-state',
1168
+ });
1169
+ expect(device.commands.typedCall.mock.calls).toEqual([
1170
+ ['ProtocolInfoRequest', 'ProtocolInfo', { eventless_wallet_session: true }],
1171
+ ['DeviceSessionAskPin', 'Success', { type: DeviceSessionPinType.AttachToPin }],
1172
+ ['DeviceStatusGet', 'DeviceStatus', {}],
1173
+ ['DeviceSessionGet', 'DeviceSession', {}],
1174
+ ]);
1175
+ expect(device.commands.typedCall).not.toHaveBeenCalledWith('DeviceSessionAskPin', 'Success', {
1176
+ type: DeviceSessionPinType.Main,
1177
+ });
1178
+ });
1179
+
1180
+ test.each([
1181
+ ['no selection', {}],
1182
+ ['an empty Host passphrase', { passphrase: '' }],
1183
+ ['more than one selection', { passphrase: 'host hidden wallet', passphraseOnDevice: true }],
1184
+ ])('rejects %s before sending a wallet selection command', async (_name, response) => {
1185
+ const typedCall = jest.fn().mockResolvedValueOnce({ message: { version: 2 } });
1186
+ const promptPassphrase = jest.fn().mockResolvedValue(response);
1187
+ const method = new OpenWalletSession({
1188
+ payload: { method: 'openWalletSession', connectId: 'connect-id', mode: 'select-hidden' },
1189
+ });
1190
+ method.init();
1191
+ method.device = createDevice({ typedCall, promptPassphrase }) as any;
1192
+
1193
+ await expect(method.run()).rejects.toMatchObject({
1194
+ errorCode: HardwareErrorCode.RuntimeError,
1195
+ message: 'Wallet selection must contain exactly one passphrase access mode.',
1196
+ });
1197
+ expect(typedCall).toHaveBeenCalledTimes(1);
1198
+ });
1199
+
1200
+ test('stops before sending a wallet command when the App cancels selection', async () => {
1201
+ const cancellation = new Error('Wallet selection cancelled');
1202
+ const typedCall = jest.fn().mockResolvedValueOnce({ message: { version: 2 } });
1203
+ const promptPassphrase = jest.fn().mockRejectedValue(cancellation);
1204
+ const method = new OpenWalletSession({
1205
+ payload: { method: 'openWalletSession', connectId: 'connect-id', mode: 'select-hidden' },
1206
+ });
1207
+ method.init();
1208
+ method.device = createDevice({ typedCall, promptPassphrase }) as any;
1209
+
1210
+ await expect(method.run()).rejects.toBe(cancellation);
1211
+ expect(typedCall).toHaveBeenCalledTimes(1);
1212
+ });
1213
+
1214
+ test.each(['User cancelled', 'Device disconnected'])(
1215
+ 'does not issue a resume request after the wallet selection reports %s',
1216
+ async message => {
1217
+ const typedCall = jest
1218
+ .fn()
1219
+ .mockResolvedValueOnce({ message: { version: 2 } })
1220
+ .mockRejectedValueOnce(new Error(message));
1221
+ const promptPassphrase = jest.fn().mockResolvedValue({ passphrase: 'host hidden wallet' });
1222
+ const method = new OpenWalletSession({
1223
+ payload: { method: 'openWalletSession', connectId: 'connect-id', mode: 'select-hidden' },
1224
+ });
1225
+ method.init();
1226
+ method.device = createDevice({ typedCall, promptPassphrase }) as any;
1227
+
1228
+ await expect(method.run()).rejects.toThrow(message);
1229
+ expect(typedCall).toHaveBeenCalledTimes(2);
1230
+ expect(typedCall).not.toHaveBeenCalledWith('DeviceSessionGet', 'DeviceSession', {});
1231
+ }
1232
+ );
1233
+
1234
+ test.each([
1235
+ ['a NUL byte', 'hidden\0wallet'],
1236
+ ['more than 50 UTF-8 bytes', 'a'.repeat(51)],
1237
+ ['more than 50 UTF-8 bytes after NFKD normalization', '\u00e9'.repeat(17)],
1238
+ ['an unpaired UTF-16 surrogate', '\ud800'],
1239
+ ])('rejects a Host passphrase containing %s', async (_name, passphrase) => {
1240
+ const typedCall = jest.fn().mockResolvedValueOnce({ message: { version: 2 } });
1241
+ const promptPassphrase = jest.fn().mockResolvedValue({ passphrase });
1242
+ const method = new OpenWalletSession({
1243
+ payload: { method: 'openWalletSession', connectId: 'connect-id', mode: 'select-hidden' },
1244
+ });
1245
+ method.init();
1246
+ method.device = createDevice({ typedCall, promptPassphrase }) as any;
1247
+
1248
+ await expect(method.run()).rejects.toMatchObject({
1249
+ errorCode: HardwareErrorCode.RuntimeError,
1250
+ message: 'Host passphrase must contain 1 to 50 valid UTF-8 bytes without NUL.',
1251
+ });
1252
+ expect(typedCall).toHaveBeenCalledTimes(1);
1253
+ });
1254
+
1255
+ test('rejects an unavailable Attach PIN selection before asking the device for a PIN', async () => {
1256
+ const typedCall = jest.fn().mockResolvedValueOnce({ message: { version: 2 } });
1257
+ const promptPassphrase = jest.fn().mockResolvedValue({ attachPinOnDevice: true });
1258
+ const method = new OpenWalletSession({
1259
+ payload: { method: 'openWalletSession', connectId: 'connect-id', mode: 'select-hidden' },
1260
+ });
1261
+ method.init();
1262
+ const device = createDevice({ typedCall, promptPassphrase });
1263
+ device.features.attachToPinEnabled = false;
1264
+ method.device = device as any;
1265
+
1266
+ await expect(method.run()).rejects.toMatchObject({
1267
+ errorCode: HardwareErrorCode.RuntimeError,
1268
+ message: 'Attach PIN wallet selection is unavailable on this device.',
1269
+ });
1270
+ expect(device.unlockDevice).not.toHaveBeenCalled();
1271
+ expect(typedCall).toHaveBeenCalledTimes(1);
1272
+ });
1273
+
1274
+ test('does not unlock or retry when wallet preparation reports a late DeviceLocked', async () => {
1275
+ const lockedError = { errorCode: HardwareErrorCode.DeviceLocked };
1276
+ const typedCall = jest
1277
+ .fn()
1278
+ .mockResolvedValueOnce({ message: { version: 2 } })
1279
+ .mockRejectedValueOnce(lockedError)
1280
+ .mockResolvedValueOnce({ message: {} })
1281
+ .mockResolvedValueOnce({
1282
+ message: { btc_test_address: 'hidden-state', session_id: 'hidden-session' },
1283
+ });
1284
+ const promptPassphrase = jest.fn().mockResolvedValue({ passphrase: 'host hidden wallet' });
1285
+ const method = new OpenWalletSession({
1286
+ payload: { method: 'openWalletSession', connectId: 'connect-id', mode: 'select-hidden' },
1287
+ });
1288
+ method.init();
1289
+ const device = createDevice({ typedCall, promptPassphrase });
1290
+ method.device = device as any;
1291
+
1292
+ await expect(method.run()).rejects.toBe(lockedError);
1293
+ expect(device.unlockDevice).not.toHaveBeenCalled();
1294
+ expect(typedCall).toHaveBeenCalledTimes(2);
1295
+ });
1296
+
1297
+ test('does not fall back when wallet preparation is rejected', async () => {
1298
+ const invalidSessionError = { errorCode: HardwareErrorCode.WalletSessionInvalid };
1299
+ const typedCall = jest
1300
+ .fn()
1301
+ .mockResolvedValueOnce({ message: { version: 2 } })
1302
+ .mockRejectedValueOnce(invalidSessionError);
1303
+ const promptPassphrase = jest.fn().mockResolvedValue({ passphrase: 'host hidden wallet' });
1304
+ const method = new OpenWalletSession({
1305
+ payload: { method: 'openWalletSession', connectId: 'connect-id', mode: 'select-hidden' },
1306
+ });
1307
+ method.init();
1308
+ const device = createDevice({ typedCall, promptPassphrase });
1309
+ method.device = device as any;
1310
+
1311
+ await expect(method.run()).rejects.toBe(invalidSessionError);
1312
+ expect(promptPassphrase).toHaveBeenCalledTimes(1);
1313
+ expect(typedCall).toHaveBeenCalledTimes(2);
1314
+ expect(device.updateInternalState).not.toHaveBeenCalled();
1315
+ });
1316
+
1317
+ test.each([
1318
+ {
1319
+ missingField: 'session_id',
1320
+ message: { btc_test_address: 'hidden-state' },
1321
+ },
1322
+ {
1323
+ missingField: 'btc_test_address',
1324
+ message: { session_id: 'hidden-session' },
1325
+ },
1326
+ ])(
1327
+ 'rejects an incomplete Protocol V2 hidden-wallet response missing $missingField',
1328
+ async ({ message }) => {
1329
+ const typedCall = jest
1330
+ .fn()
1331
+ .mockResolvedValueOnce({ message: { version: 2 } })
1332
+ .mockResolvedValueOnce({ message: {} })
1333
+ .mockResolvedValueOnce({ message });
1334
+ const promptPassphrase = jest.fn().mockResolvedValue({ passphrase: 'host hidden wallet' });
1335
+ const method = new OpenWalletSession({
1336
+ payload: { method: 'openWalletSession', connectId: 'connect-id', mode: 'select-hidden' },
1337
+ });
1338
+ method.init();
1339
+ const device = createDevice({ typedCall, promptPassphrase });
1340
+ method.device = device as any;
1341
+
1342
+ await expect(method.run()).rejects.toMatchObject({
1343
+ errorCode: HardwareErrorCode.RuntimeError,
1344
+ message: 'Device returned an incomplete DeviceSession response.',
1345
+ });
1346
+ expect(device.clearInternalState).toHaveBeenCalled();
1347
+ expect(device.updateInternalState).not.toHaveBeenCalled();
1348
+ }
1349
+ );
1350
+
1351
+ test('resumes a known hidden wallet without prompting or device selection', async () => {
1352
+ const typedCall = jest
1353
+ .fn()
1354
+ .mockResolvedValueOnce({ message: { version: 2 } })
1355
+ .mockResolvedValueOnce({
1356
+ message: {
1357
+ btc_test_address: 'hidden-state',
1358
+ session_id: 'renewed-session',
1359
+ },
1360
+ });
1361
+ const promptPassphrase = jest.fn();
1362
+ const method = new OpenWalletSession({
1363
+ payload: {
1364
+ method: 'openWalletSession',
1365
+ connectId: 'connect-id',
1366
+ mode: 'resume-hidden',
1367
+ deviceId: 'device-1',
1368
+ passphraseState: 'hidden-state',
1369
+ },
1370
+ });
1371
+ method.init();
1372
+ deviceWalletSessionStore.set('device-1', 'hidden-state', 'known-session');
1373
+ method.device = createDevice({ typedCall, promptPassphrase }) as any;
1374
+
1375
+ await expect(method.run()).resolves.toEqual({
1376
+ protocol: 'V2',
1377
+ walletType: 'hidden',
1378
+ deviceId: 'device-1',
1379
+ passphraseState: 'hidden-state',
1380
+ resumed: true,
1381
+ });
1382
+ expect(typedCall).toHaveBeenCalledWith('DeviceSessionGet', 'DeviceSession', {
1383
+ session_id: 'known-session',
1384
+ });
1385
+ expect(promptPassphrase).not.toHaveBeenCalled();
1386
+ });
1387
+
1388
+ test('validates a locked Protocol V2 resume binding after deviceId refresh', async () => {
1389
+ const typedCall = jest
1390
+ .fn()
1391
+ .mockResolvedValueOnce({ message: { version: 2 } })
1392
+ .mockResolvedValueOnce({
1393
+ message: {
1394
+ btc_test_address: 'hidden-state',
1395
+ session_id: 'renewed-session',
1396
+ },
1397
+ });
1398
+ const method = new OpenWalletSession({
1399
+ payload: {
1400
+ method: 'openWalletSession',
1401
+ connectId: 'connect-id',
1402
+ mode: 'resume-hidden',
1403
+ deviceId: 'device-1',
1404
+ passphraseState: 'hidden-state',
1405
+ },
1406
+ });
1407
+ method.init();
1408
+ deviceWalletSessionStore.set('device-1', 'hidden-state', 'known-session');
1409
+ const device = createDevice({ typedCall });
1410
+ device.features.unlocked = false;
1411
+ device.getDeviceState = jest
1412
+ .fn()
1413
+ .mockResolvedValueOnce({
1414
+ identity: { deviceId: undefined },
1415
+ status: { unlocked: false, passphraseProtection: true },
1416
+ })
1417
+ .mockResolvedValueOnce({
1418
+ identity: { deviceId: 'device-1' },
1419
+ status: {
1420
+ unlocked: true,
1421
+ passphraseProtection: true,
1422
+ unlockedAttachPin: false,
1423
+ },
1424
+ });
1425
+ device.unlockDevice = jest.fn().mockImplementation(() => {
1426
+ device.features.unlocked = true;
1427
+ return Promise.resolve(device.features);
1428
+ });
1429
+ method.device = device as any;
1430
+
1431
+ await expect(method.run()).resolves.toMatchObject({
1432
+ protocol: 'V2',
1433
+ walletType: 'hidden',
1434
+ deviceId: 'device-1',
1435
+ passphraseState: 'hidden-state',
1436
+ resumed: true,
1437
+ });
1438
+ expect(device.unlockDevice).toHaveBeenCalledTimes(1);
1439
+ expect(device.getDeviceState).toHaveBeenCalledTimes(2);
1440
+ expect(typedCall).toHaveBeenCalledWith('DeviceSessionGet', 'DeviceSession', {
1441
+ session_id: 'known-session',
1442
+ });
1443
+ const sessionGetCall = typedCall.mock.calls.findIndex(
1444
+ ([requestName]) => requestName === 'DeviceSessionGet'
1445
+ );
1446
+ expect(device.getDeviceState.mock.invocationCallOrder[1]).toBeLessThan(
1447
+ typedCall.mock.invocationCallOrder[sessionGetCall]
1448
+ );
1449
+ });
1450
+
1451
+ test('rejects a Protocol V2 resume when the refreshed deviceId does not match', async () => {
1452
+ const typedCall = jest.fn().mockResolvedValue({
1453
+ message: {
1454
+ btc_test_address: 'hidden-state',
1455
+ session_id: 'renewed-session',
1456
+ },
1457
+ });
1458
+ const method = new OpenWalletSession({
1459
+ payload: {
1460
+ method: 'openWalletSession',
1461
+ connectId: 'connect-id',
1462
+ mode: 'resume-hidden',
1463
+ deviceId: 'device-1',
1464
+ passphraseState: 'hidden-state',
1465
+ },
1466
+ });
1467
+ method.init();
1468
+ deviceWalletSessionStore.set('device-1', 'hidden-state', 'known-session');
1469
+ const device = createDevice({ typedCall });
1470
+ device.features.unlocked = false;
1471
+ device.getDeviceState = jest
1472
+ .fn()
1473
+ .mockResolvedValueOnce({
1474
+ identity: { deviceId: undefined },
1475
+ status: { passphraseProtection: true },
1476
+ })
1477
+ .mockResolvedValueOnce({
1478
+ identity: { deviceId: 'other-device' },
1479
+ status: {
1480
+ unlocked: true,
1481
+ passphraseProtection: true,
1482
+ unlockedAttachPin: false,
1483
+ },
1484
+ });
1485
+ device.unlockDevice = jest.fn().mockImplementation(() => {
1486
+ device.features.unlocked = true;
1487
+ return Promise.resolve(device.features);
1488
+ });
1489
+ method.device = device as any;
1490
+
1491
+ await expect(method.run()).rejects.toMatchObject({
1492
+ errorCode: HardwareErrorCode.DeviceCheckDeviceIdError,
1493
+ });
1494
+ expect(typedCall).not.toHaveBeenCalled();
1495
+ expect(device.clearInternalState).not.toHaveBeenCalled();
1496
+ expect(deviceWalletSessionStore.get('device-1', 'hidden-state')).toBeUndefined();
1497
+ });
1498
+
1499
+ test('reselects the expected hidden wallet when a cached Protocol V2 session is invalid', async () => {
1500
+ const typedCall = jest
1501
+ .fn()
1502
+ .mockResolvedValueOnce({ message: { version: 2 } })
1503
+ .mockRejectedValueOnce(
1504
+ Object.assign(new Error('Invalid session'), {
1505
+ errorCode: HardwareErrorCode.WalletSessionInvalid,
1506
+ })
1507
+ )
1508
+ .mockResolvedValueOnce({ message: {} })
1509
+ .mockResolvedValueOnce({
1510
+ message: {
1511
+ btc_test_address: 'hidden-state',
1512
+ session_id: 'renewed-session',
1513
+ },
1514
+ });
1515
+ const promptPassphrase = jest.fn().mockResolvedValue({ passphrase: 'host hidden wallet' });
1516
+ const method = new OpenWalletSession({
1517
+ payload: {
1518
+ method: 'openWalletSession',
1519
+ connectId: 'connect-id',
1520
+ mode: 'resume-hidden',
1521
+ deviceId: 'device-1',
1522
+ passphraseState: 'hidden-state',
1523
+ },
1524
+ });
1525
+ method.init();
1526
+ deviceWalletSessionStore.set('device-1', 'hidden-state', 'expired-session');
1527
+ method.device = createDevice({ typedCall, promptPassphrase }) as any;
1528
+
1529
+ await expect(method.run()).resolves.toEqual({
1530
+ protocol: 'V2',
1531
+ walletType: 'hidden',
1532
+ deviceId: 'device-1',
1533
+ passphraseState: 'hidden-state',
1534
+ resumed: false,
1535
+ });
1536
+ expect(typedCall).toHaveBeenCalledWith('DeviceSessionGet', 'DeviceSession', {
1537
+ session_id: 'expired-session',
1538
+ });
1539
+ expect(promptPassphrase).toHaveBeenCalledTimes(1);
1540
+ expect(deviceWalletSessionStore.get('device-1', 'hidden-state')).toBe('renewed-session');
1541
+ });
1542
+
1543
+ test('selects the expected hidden wallet when Protocol V2 has no cached session', async () => {
1544
+ const typedCall = jest
1545
+ .fn()
1546
+ .mockResolvedValueOnce({ message: { version: 2 } })
1547
+ .mockResolvedValueOnce({
1548
+ message: {
1549
+ btc_test_address: 'hidden-state',
1550
+ session_id: 'new-session',
1551
+ },
1552
+ });
1553
+ const promptPassphrase = jest.fn().mockResolvedValue({ passphrase: 'host hidden wallet' });
1554
+ const method = new OpenWalletSession({
1555
+ payload: {
1556
+ method: 'openWalletSession',
1557
+ connectId: 'connect-id',
1558
+ mode: 'resume-hidden',
1559
+ deviceId: 'device-1',
1560
+ passphraseState: 'hidden-state',
1561
+ },
1562
+ });
1563
+ method.init();
1564
+ method.device = createDevice({ typedCall, promptPassphrase }) as any;
1565
+
1566
+ await expect(method.run()).resolves.toEqual({
1567
+ protocol: 'V2',
1568
+ walletType: 'hidden',
1569
+ deviceId: 'device-1',
1570
+ passphraseState: 'hidden-state',
1571
+ resumed: false,
1572
+ });
1573
+ expect(typedCall).toHaveBeenCalledWith('DeviceSessionGet', 'DeviceSession', {});
1574
+ expect(promptPassphrase).not.toHaveBeenCalled();
1575
+ expect(deviceWalletSessionStore.get('device-1', 'hidden-state')).toBe('new-session');
1576
+ });
1577
+
1578
+ test.each([false, true])('keeps deriveCardano API compatibility: %s', async deriveCardano => {
1579
+ const typedCall = jest
1580
+ .fn()
1581
+ .mockResolvedValueOnce({ message: { version: 2 } })
1582
+ .mockResolvedValueOnce({ message: {} })
1583
+ .mockResolvedValueOnce({
1584
+ message: {
1585
+ btc_test_address: 'hidden-state',
1586
+ session_id: 'new-session',
1587
+ },
1588
+ });
1589
+ const method = new OpenWalletSession({
1590
+ payload: {
1591
+ method: 'openWalletSession',
1592
+ connectId: 'connect-id',
1593
+ mode: 'select-hidden',
1594
+ deriveCardano,
1595
+ },
1596
+ });
1597
+ method.init();
1598
+ method.device = createDevice({
1599
+ typedCall,
1600
+ promptPassphrase: jest.fn().mockResolvedValue({ passphrase: 'host hidden wallet' }),
1601
+ }) as any;
1602
+
1603
+ await expect(method.run()).resolves.toMatchObject({
1604
+ walletType: 'hidden',
1605
+ passphraseState: 'hidden-state',
1606
+ });
1607
+ expect(typedCall).toHaveBeenCalledWith('DeviceSessionGet', 'DeviceSession', {});
1608
+ });
1609
+ });