async def export_keys( self, # type: HummingbotApplication ): if not Security.any_encryped_files() and not Security.any_wallets(): self._notify("There are no keys to export.") return await Security.wait_til_decryption_done() self.placeholder_mode = True self.app.hide_input = True if await self.check_password(): await Security.wait_til_decryption_done() self._notify( "\nWarning: Never disclose API keys or private keys. Anyone with your keys can steal any " "assets held in your account.") if Security.all_decrypted_values(): self._notify("\nAPI keys:") for key, value in Security.all_decrypted_values().items(): self._notify(f"{key}: {value}") if Security.private_keys(): self._notify("\nEthereum wallets:") for key, value in Security.private_keys().items(): self._notify( f"Public address: {key}\nPrivate Key: {value.hex()}") self.app.change_prompt(prompt=">>> ") self.app.hide_input = False self.placeholder_mode = False
def test_new_password_process(self): # empty folder, new password is required self.assertFalse(Security.any_encryped_files()) self.assertTrue(Security.new_password_required()) # login will pass with any password result = Security.login("a") self.assertTrue(result) Security.update_secure_config("new_key", "new_value") self.assertTrue(os.path.exists(f"{temp_folder}encrypted_new_key.json")) self.assertTrue(Security.encrypted_file_exists("new_key"))
async def _test_existing_password(self): # check the 2 encrypted files exist self.assertTrue( os.path.exists(f"{temp_folder}encrypted_test_key_1.json")) self.assertTrue( os.path.exists(f"{temp_folder}encrypted_test_key_2.json")) self.assertTrue(Security.any_encryped_files()) self.assertFalse(Security.new_password_required()) # login fails with incorrect password result = Security.login("b") self.assertFalse(result) # login passes with correct password result = Security.login("a") self.assertTrue(result) # right after logging in, the decryption shouldn't finished yet self.assertFalse(Security.is_decryption_done()) await Security.wait_til_decryption_done() self.assertEqual(len(Security.all_decrypted_values()), 2) config_value = Security.decrypted_value("test_key_1") self.assertEqual("test_value_1", config_value) Security.update_secure_config("test_key_1", "new_value") self.assertEqual("new_value", Security.decrypted_value("test_key_1"))