diff --git a/src/seedsigner/models/seed.py b/src/seedsigner/models/seed.py index 5d02ac46a..a3858debe 100644 --- a/src/seedsigner/models/seed.py +++ b/src/seedsigner/models/seed.py @@ -134,10 +134,14 @@ def reverse_bytes(self): self._generate_seed() def seed_xor(self, other): - if len(self.mnemonic_list) != len(other.mnemonic_list): + self_entropy = bip39.mnemonic_to_bytes(self.mnemonic_str) + other_entropy = bip39.mnemonic_to_bytes(other.mnemonic_str) + if len(self_entropy) != len(other_entropy): raise Exception("XOR requires seeds of similar mnemonic length!") - if self.mnemonic_list == other.mnemonic_list: + if self_entropy == other_entropy: raise Exception("You may not XOR a seed with itself.") + if self_entropy == inv_bits(other_entropy): + raise Exception("You may not XOR a seed with its inversion.") new_entropy = xor_bytes(self.entropy, other.entropy) self._mnemonic = bip39.mnemonic_from_bytes(new_entropy).split() self._generate_seed() diff --git a/src/seedsigner/views/seed_views.py b/src/seedsigner/views/seed_views.py index 512e2caac..f734a2f98 100644 --- a/src/seedsigner/views/seed_views.py +++ b/src/seedsigner/views/seed_views.py @@ -311,7 +311,11 @@ def run(self): REVERSE_BYTES = "Reverse bytes" SEED_XOR = "Seed XOR" button_data = [INVERT_BITS, REVERSE_BITS, REVERSE_BYTES] - if len([x for x in self.controller.storage.seeds if len(x.mnemonic_list) == len(self.seed.mnemonic_list)]): + # todo: in 3 places, make it just 1 + if len([x for x in self.controller.storage.seeds + if len(x.mnemonic_list) == len(self.seed.mnemonic_list) \ + and x.mnemonic_list != self.seed.mnemonic_list \ + and len(x.passphrase) == 0]): button_data.append(SEED_XOR) ret = ButtonListScreen( @@ -346,8 +350,12 @@ def run(self): text = "Select seed to XOR with" button_data = [] for seed in seeds: - button_str = seed.get_fingerprint(self.settings.get_value(SettingsConstants.SETTING__NETWORK)) - button_data.append((button_str, SeedSignerCustomIconConstants.FINGERPRINT, "blue")) + # todo: in 3 places, make it just 1 + if len(seed.mnemonic_list) == len(self.seed.mnemonic_list) \ + and seed.mnemonic_list != self.seed.mnemonic_list \ + and len(seed.passphrase) == 0: + button_str = seed.get_fingerprint(self.settings.get_value(SettingsConstants.SETTING__NETWORK)) + button_data.append((button_str, SeedSignerCustomIconConstants.FINGERPRINT, "blue")) selected_menu_num = seed_screens.SeedSelectSeedScreen( title=title, @@ -368,7 +376,11 @@ class SeedXORApplyView(View): def __init__(self, seed_num: int = None): super().__init__() self.seed = self.controller.storage.get_pending_seed() - seeds = [x for x in self.controller.storage.seeds if len(x.mnemonic_list) == len(self.seed.mnemonic_list)] + # todo: in 3 places, make it just 1 + seeds = [x for x in self.controller.storage.seeds + if len(x.mnemonic_list) == len(self.seed.mnemonic_list) \ + and x.mnemonic_list != self.seed.mnemonic_list \ + and len(x.passphrase) == 0] if seed_num is not None: self.other = seeds[seed_num]