async def keyring_status(self) -> Dict[str, Any]: passphrase_support_enabled: bool = supports_keyring_passphrase() user_passphrase_is_set: bool = not using_default_passphrase() locked: bool = Keychain.is_keyring_locked() needs_migration: bool = Keychain.needs_migration() response: Dict[str, Any] = { "success": True, "is_keyring_locked": locked, "passphrase_support_enabled": passphrase_support_enabled, "user_passphrase_is_set": user_passphrase_is_set, "needs_migration": needs_migration, } return response
async def migrate_keyring(self, request: Dict[str, Any]) -> Dict[str, Any]: if Keychain.needs_migration() is False: # If the keyring has already been migrated, we'll raise an error to the client. # The reason for raising an error is because the migration request has side- # effects beyond copying keys from the legacy keyring to the new keyring. The # request may have set a passphrase and indicated that keys should be cleaned # from the legacy keyring. If we were to return early and indicate success, # the client and user's expectations may not match reality (were my keys # deleted from the legacy keyring? was my passphrase set?). return {"success": False, "error": "migration not needed"} success: bool = False error: Optional[str] = None passphrase: Optional[str] = request.get("passphrase", None) cleanup_legacy_keyring: bool = request.get("cleanup_legacy_keyring", False) if passphrase is not None and type(passphrase) is not str: return {"success": False, "error": 'expected string value for "passphrase"'} if not Keychain.passphrase_meets_requirements(passphrase): return {"success": False, "error": "passphrase doesn't satisfy requirements"} if type(cleanup_legacy_keyring) is not bool: return {"success": False, "error": 'expected bool value for "cleanup_legacy_keyring"'} try: Keychain.migrate_legacy_keyring(passphrase=passphrase, cleanup_legacy_keyring=cleanup_legacy_keyring) success = True # Inform the GUI of keyring status changes self.keyring_status_changed(await self.keyring_status(), "wallet_ui") except Exception as e: tb = traceback.format_exc() self.log.error(f"Legacy keyring migration failed: {e} {tb}") error = f"keyring migration failed: {e}" response: Dict[str, Any] = {"success": success, "error": error} return response