-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add minimal backup app, minor keystorage improvements for multi-seed
- Loading branch information
1 parent
40e79dc
commit a2e89e3
Showing
4 changed files
with
79 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
""" | ||
Backup app - can load secrets from a text file or qr code that starts with | ||
bip39: <recovery phrase> | ||
""" | ||
from app import BaseApp, AppError | ||
from io import BytesIO | ||
from binascii import hexlify | ||
from rng import get_random_bytes | ||
from bitcoin import bip39 | ||
from gui.screens import Prompt | ||
from gui.components.mnemonic import MnemonicTable | ||
import lvgl as lv | ||
|
||
# Should be called App if you use a single file | ||
class App(BaseApp): | ||
"""Allows to load mnemonic from text file / QR code""" | ||
name = "backup" | ||
prefixes = [b"bip39:"] | ||
|
||
async def process_host_command(self, stream, show_fn): | ||
# reads prefix from the stream (until first space) | ||
prefix = self.get_prefix(stream) | ||
if prefix not in self.prefixes: | ||
# WTF? It's not our data... | ||
raise AppError("Prefix is not valid: %s" % prefix.decode()) | ||
mnemonic = stream.read().strip().decode() | ||
if not bip39.mnemonic_is_valid(mnemonic): | ||
raise AppError("Invalid mnemonic!") | ||
scr = Prompt("Load this mnemonic to memory?", "Mnemonic:") | ||
table = MnemonicTable(scr) | ||
table.align(scr.message, lv.ALIGN.OUT_BOTTOM_MID, 0, 30) | ||
table.set_mnemonic(mnemonic) | ||
if await show_fn(scr): | ||
self.keystore.set_mnemonic(mnemonic) | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters