@onekeyfe/hd-core 1.2.0-alpha.5 → 1.2.0-alpha.50

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