Skip to content

Commit

Permalink
Merge pull request #157 from moneymanolis/bip39-wordlist
Browse files Browse the repository at this point in the history
UX upgrades to new key screen and easier display of recovery phrase
  • Loading branch information
stepansnigirev authored Jun 10, 2021
2 parents ed59dd7 + bea5a4c commit 2fada0f
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 66 deletions.
16 changes: 8 additions & 8 deletions src/gui/screens/mnemonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


class MnemonicScreen(Screen):
def __init__(self, mnemonic="", title="Your recovery phrase", note=None):
def __init__(self, mnemonic="", title="Your recovery phrase:", note=None):
super().__init__()
self.title = add_label(title, scr=self, style="title")
if note is not None:
Expand All @@ -30,7 +30,7 @@ def __init__(
wordlist,
fixer,
title="Your recovery phrase:",
note="Write it down and never show to anybody.",
note="Write it down and never show it to anybody.",
):
self.fixer = fixer
self.wordlist = wordlist
Expand All @@ -42,11 +42,11 @@ def __init__(
self.table.set_click(True)

self.close_label.set_text(lv.SYMBOL.LEFT + " Back")
self.next_button = add_button(scr=self, callback=on_release(self.confirm))
self.done_button = add_button(scr=self, callback=on_release(self.confirm))

self.next_label = lv.label(self.next_button)
self.next_label.set_text("Next " + lv.SYMBOL.RIGHT)
align_button_pair(self.close_button, self.next_button)
self.done_label = lv.label(self.done_button)
self.done_label.set_text(lv.SYMBOL.OK + " Done")
align_button_pair(self.close_button, self.done_button)

# toggle switch 12-24 words
lbl = lv.label(self)
Expand Down Expand Up @@ -99,7 +99,7 @@ def change_word(self, idx):
word = self.table.words[idx]
self.instruction.set_text(
"Changing word number %d:\n%s (%d in wordlist)"
% (idx+1, word.upper(), self.wordlist.index(word))
% (idx+1, word.upper(), self.wordlist.index(word)+1)
)
# hide switch
if not self.switch.get_hidden():
Expand Down Expand Up @@ -132,7 +132,7 @@ def cb(obj, event):
self.table.set_mnemonic(self.fixer(mnemonic))
self.instruction.set_text(
"Changing word number %d:\n%s (%d in wordlist)"
% (idx+1, word.upper(), self.wordlist.index(word))
% (idx+1, word.upper(), self.wordlist.index(word)+1)
)
self.kb.set_event_cb(cb)

Expand Down
6 changes: 2 additions & 4 deletions src/keystore/flash.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,13 @@ async def init(self, show_fn, show_loader):
await super().init(show_fn, show_loader)

async def storage_menu(self):
"""Manage storage and display of the recovery phrase"""
"""Manage storage"""
buttons = [
# id, text
(None, "Key management"),
(0, "Save key to flash"),
(1, "Load key from flash"),
(2, "Delete key from flash"),
(3, "Show recovery phrase"),
]

# we stay in this menu until back is pressed
Expand Down Expand Up @@ -275,5 +274,4 @@ async def storage_menu(self):
"Success!", "Your key is deleted from flash.", button_text="OK"
)
)
elif menuitem == 3:
await self.show_mnemonic()

6 changes: 2 additions & 4 deletions src/keystore/memorycard.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,15 +313,14 @@ async def init(self, show_fn, show_loader):
await super().init(show_fn, show_loader)

async def storage_menu(self):
"""Manage storage and display of the recovery phrase"""
"""Manage storage"""
enabled = self.connection.isCardInserted()
buttons = [
# id, text
(None, "Smartcard storage"),
(0, "Save key to the card", enabled),
(1, "Load key from the card", enabled),
(2, "Delete key from the card", enabled),
(3, "Show recovery phrase"),
]

# we stay in this menu until back is pressed
Expand Down Expand Up @@ -355,5 +354,4 @@ async def storage_menu(self):
button_text="OK",
)
)
elif menuitem == 3:
await self.show_mnemonic()

42 changes: 1 addition & 41 deletions src/keystore/ram.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ class RAMKeyStore(KeyStore):
_set_pin, _unlock, _change_pin and other pin-related methods.
"""

# Button to go to storage menu
# Menu should be implemented in async storage_menu function
# Here we only have a single option - to show mnemonic
storage_button = "Show mnemonic"
storage_button = None

def __init__(self):
# bip39 mnemonic
Expand Down Expand Up @@ -352,40 +349,3 @@ async def show_mnemonic(self):
self.lock()
await self.unlock()
await self.show(MnemonicScreen(self.mnemonic))

async def storage_menu(self):
"""Manage storage and display of the recovery phrase"""
# This class can only show mnemonic, can't save
await self.show_mnemonic()
"""
# Example:
buttons = [
# id, text
(None, "Key management"),
(0, "Save key to flash"),
(1, "Load key from flash"),
(2, "Delete key from flash"),
(3, "Show recovery phrase"),
]
# wait for menu selection
menuitem = await self.show(Menu(buttons, last=(255, None)))
# process the menu button:
# back button
if menuitem == 255:
pass
elif menuitem == 0:
await self.save_mnemonic()
await self.show(Alert("Success!",
"Your key is stored in flash now."))
elif menuitem == 1:
await self.load_mnemonic()
await self.show(Alert("Success!",
"Your key is loaded."))
elif menuitem == 2:
await self.delete_mnemonic()
await self.show(Alert("Success!",
"Your key is deleted from flash."))
elif menuitem == 3:
await self.show(MnemonicScreen(self.mnemonic))
"""
7 changes: 2 additions & 5 deletions src/keystore/sdcard.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,13 @@ async def delete_mnemonic(self, path=None):
return True

async def storage_menu(self):
"""Manage storage and display of the recovery phrase"""
"""Manage storage"""
buttons = [
# id, text
(None, "Manage keys on SD card and internal flash"),
(0, "Save key"),
(1, "Load key"),
(2, "Delete key"),
(None, "Other"),
(3, "Show recovery phrase"),
]

# we stay in this menu until back is pressed
Expand All @@ -162,5 +160,4 @@ async def storage_menu(self):
await self.show(
Alert("Success!", "Your key is deleted.", button_text="OK")
)
elif menuitem == 3:
await self.show_mnemonic()

12 changes: 8 additions & 4 deletions src/specter.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,17 +276,19 @@ async def settingsmenu(self):
(None, "Key management"),
]
if self.keystore.storage_button is not None:
buttons.append((0, self.keystore.storage_button))
buttons.extend([(2, "Enter BIP-39 password"), (None, "Security")]) # delimiter
buttons.extend([(4, "Device settings")])
buttons.append((1, self.keystore.storage_button))
buttons.append((2, "Enter BIP-39 password"))
if hasattr(self.keystore, "show_mnemonic"):
buttons.append((3, "Show recovery phrase"))
buttons.extend([(None, "Security"), (4, "Device settings")]) # delimiter
# wait for menu selection
menuitem = await self.gui.menu(buttons, last=(255, None), note="Firmware version %s" % get_version())

# process the menu button:
# back button
if menuitem == 255:
return self.mainmenu
elif menuitem == 0:
elif menuitem == 1:
await self.keystore.storage_menu()
elif menuitem == 2:
pwd = await self.gui.get_input()
Expand All @@ -295,6 +297,8 @@ async def settingsmenu(self):
self.keystore.set_mnemonic(password=pwd)
for app in self.apps:
app.init(self.keystore, self.network, self.gui.show_loader)
elif menuitem == 3:
await self.keystore.show_mnemonic()
elif menuitem == 4:
await self.update_devsettings()
elif menuitem == 5:
Expand Down

0 comments on commit 2fada0f

Please sign in to comment.