From 60544359126c72c20b889c211cc80a34b94ebf97 Mon Sep 17 00:00:00 2001 From: chris-belcher Date: Tue, 1 Jun 2021 14:39:59 +0100 Subject: [PATCH] Attempt to use empty imported addresses as change Previously when spending coins on imported-key wallets, the change address would always be an address from one of the inputs. This address reuse is pretty bad for privacy because it leaks which output is change. This commit attempts to find unused imported addresses, and if there are any then use them as change addresses. The practical use-case I considered was the situation when using the Electrum android app to do a cash-in-person trade. Some people might want to bring only one of their UTXOs to the meetup for safety. This commit allows them to import that one UTXO plus an unused change address, allowing them to create a transaction without address reuse. --- electrum/wallet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/electrum/wallet.py b/electrum/wallet.py index a8bca07864e0..f0db4a673e16 100644 --- a/electrum/wallet.py +++ b/electrum/wallet.py @@ -2681,7 +2681,7 @@ def get_receiving_addresses(self, **kwargs): return self.get_addresses() def get_change_addresses(self, **kwargs): - return [] + return [addr for addr in self.get_addresses() if len(self.db.get_addr_history(addr)) == 0] def import_addresses(self, addresses: List[str], *, write_to_disk=True) -> Tuple[List[str], List[Tuple[str, str]]]: