Skip to content

Commit

Permalink
partial impl. of dipunm's feedback in issue SeedSigner#43
Browse files Browse the repository at this point in the history
* Not even offered to SeedXOR against itself.
* Cannot SeedXOR against a seed's inversion.
* Cannot SeedXOR against a seed w/ passphrase.
  • Loading branch information
Jean Do committed Jan 18, 2023
1 parent 3326100 commit afd0591
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/seedsigner/models/seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
20 changes: 16 additions & 4 deletions src/seedsigner/views/seed_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand All @@ -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]

Expand Down

0 comments on commit afd0591

Please sign in to comment.