From d950e21578187efdd1f2bf0f8a018f54961834d4 Mon Sep 17 00:00:00 2001 From: Nick Klockenga Date: Thu, 6 May 2021 14:31:06 -0400 Subject: [PATCH] refactoring of seedsigner to a move MVC application model with a few additional minor enhancements --- .gitignore | 1 + controller.py | 417 +++++ ST7789.py => helpers/ST7789.py | 1 - helpers/buttons.py | 82 + helpers/camera_process.py | 80 + helpers/path.py | 29 + helpers/psbt_signer.py | 331 ++++ helpers/qr.py | 49 + main.py | 52 +- models/seed_storage.py | 144 ++ resources.py | 3156 -------------------------------- views/io_test_view.py | 141 ++ views/menu_view.py | 318 ++++ views/seed_tools_view.py | 575 ++++++ views/settings_tools_view.py | 72 + views/signing_tools_view.py | 105 ++ views/view.py | 187 ++ 17 files changed, 2541 insertions(+), 3199 deletions(-) create mode 100644 .gitignore create mode 100644 controller.py rename ST7789.py => helpers/ST7789.py (96%) create mode 100644 helpers/buttons.py create mode 100644 helpers/camera_process.py create mode 100644 helpers/path.py create mode 100644 helpers/psbt_signer.py create mode 100644 helpers/qr.py create mode 100644 models/seed_storage.py delete mode 100644 resources.py create mode 100644 views/io_test_view.py create mode 100644 views/menu_view.py create mode 100644 views/seed_tools_view.py create mode 100644 views/settings_tools_view.py create mode 100644 views/signing_tools_view.py create mode 100644 views/view.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..e43b0f98 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/controller.py b/controller.py new file mode 100644 index 00000000..3db1718b --- /dev/null +++ b/controller.py @@ -0,0 +1,417 @@ +# External Dependencies +import time +from multiprocessing import Process, Queue +from subprocess import call + +# Internal file class dependencies +from view import View +from menu_view import MenuView +from seed_tools_view import SeedToolsView +from signing_tools_view import SigningToolsView +from settings_tools_view import SettingsToolsView +from io_test_view import IOTestView +from buttons import Buttons, B +from camera_process import CameraProcess +from path import Path +from seed_storage import SeedStorage +from psbt_signer import PSBTSigner + +class Controller: + + VERSION = "0.4.0b3" + + def __init__(self) -> None: + controller = self + + # Input Buttons + self.buttons = Buttons() + + # models + self.storage = SeedStorage("main", "m/48h/0h/0h/2h") + + # Views + self.menu_view = MenuView(controller) + self.seed_tools_view = SeedToolsView(controller) + self.io_test_view = IOTestView(controller) + self.signing_tools_view = SigningToolsView(controller, self.storage) + self.settings_tools_view = SettingsToolsView(controller) + + # Then start seperate background camera process with two queues for communication + # CameraProcess handles connecting to camera hardware and passing back barcode data via from camera queue + self.from_camera_queue = Queue() + self.to_camera_queue = Queue() + p = Process(target=CameraProcess.start, args=(self.from_camera_queue, self.to_camera_queue)) + p.start() + + return + + def start(self, debug = False) -> None: + + if debug == False: + crash_cnt = 0 + + # Handle Unexpected crashes by restarting up to 3 times + while True: + try: + self.show_main_menu() + except Exception as error: + if crash_cnt >= 3: + break + else: + print('Caught this error: ' + repr(error)) # debug + self.menu_view.draw_modal(["Crashed ..."], "", "restarting") + time.sleep(5) + + crash_cnt += 1 + + self.menu_view.draw_modal(["Crashed ..."], "", "requires hard restart") + else: + self.show_main_menu() + + ### Menu + ### Menu View handles navigation within the menu + ### Sub Menu's like Seed Tools, Signing Tools, Settings are all in the Menu View + + def show_main_menu(self, sub_menu = 0): + ret_val = sub_menu + while True: + ret_val = self.menu_view.display_main_menu(ret_val) + + if ret_val == Path.MAIN_MENU: + ret_val = Path.MAIN_MENU + elif ret_val == Path.GEN_LAST_WORD: + ret_val = self.show_generate_last_word_tool() + elif ret_val == Path.DICE_GEN_SEED: + ret_val = self.show_create_seed_with_dice_tool() + elif ret_val == Path.SAVE_SEED: + ret_val = self.show_store_a_seed_tool() + elif ret_val == Path.GEN_XPUB: + ret_val = self.show_generate_xpub() + elif ret_val == Path.SIGN_TRANSACTION: + ret_val = self.show_sign_transaction() + elif ret_val == Path.IO_TEST_TOOL: + ret_val = self.show_io_test_tool() + elif ret_val == Path.VERSION_INFO: + ret_val = self.show_version_info() + elif ret_val == Path.CURRENT_NETWORK: + ret_val = self.show_current_network_tool() + elif ret_val == Path.WALLET: + ret_val = self.show_wallet_tool() + elif ret_val == Path.DONATE: + ret_val = self.show_donate_tool() + elif ret_val == Path.POWER_OFF: + ret_val = self.show_power_off() + + print("exit show_main_menu") + return # should never return/exit + + ### Power Off + + def show_power_off(self): + + r = self.menu_view.display_generic_selection_menu(["Yes", "No"], "Power Off?") + if r == 1: #Yes + self.menu_view.display_power_off_screen() + call("sudo shutdown --poweroff now", shell=True) + time.sleep(10) + else: # No + return Path.MAIN_MENU + + ### + ### Seed Tools Controller Naviation/Launcher + ### + + ### Generate Last Word 12 / 24 Menu + + def show_generate_last_word_tool(self) -> int: + seed_phrase = [] + ret_val = 0 + + while True: + # display menu to select 12 or 24 word seed for last word + ret_val = self.menu_view.display_12_24_word_menu("... [ Return to Seed Tools ]") + if ret_val == Path.SEED_WORD_12: + seed_phrase = self.seed_tools_view.display_gather_words_screen(11) + elif ret_val == Path.SEED_WORD_24: + seed_phrase = self.seed_tools_view.display_gather_words_screen(23) + else: + return Path.SEED_TOOLS_SUB_MENU + + if len(seed_phrase) > 0: + completed_seed_phrase = self.seed_tools_view.display_last_word(seed_phrase) + break + + # Ask to save seed + if self.storage.slot_avaliable(): + r = self.menu_view.display_generic_selection_menu(["Yes", "No"], "Save Seed?") + if r == 1: #Yes + slot_num = self.menu_view.display_saved_seed_menu(self.storage,2,None) + if slot_num in (1,2,3): + self.storage.save_seed_phrase(completed_seed_phrase, slot_num) + self.menu_view.draw_modal(["Seed Valid", "Saved to Slot #" + str(slot_num)], "", "Right to Continue") + input = self.buttons.wait_for([B.KEY_RIGHT]) + + return Path.MAIN_MENU + + ### Create a Seed w/ Dice Screen + + def show_create_seed_with_dice_tool(self) -> int: + seed_phrase = [] + ret_val = True + + while True: + seed_phrase = self.seed_tools_view.display_generate_seed_from_dice() + if len(seed_phrase) > 0: + break + else: + return Path.SEED_TOOLS_SUB_MENU + + # display seed phrase (24 words) + while True: + ret_val = self.seed_tools_view.display_seed_phrase(seed_phrase, "Right to Continue") + if ret_val == True: + break + + # Ask to save seed + if self.storage.slot_avaliable(): + r = self.menu_view.display_generic_selection_menu(["Yes", "No"], "Save Seed?") + if r == 1: #Yes + slot_num = self.menu_view.display_saved_seed_menu(self.storage,2,None) + if slot_num in (1,2,3): + self.storage.save_seed_phrase(seed_phrase, slot_num) + self.menu_view.draw_modal(["Seed Valid", "Saved to Slot #" + str(slot_num)], "", "Right to Continue") + input = self.buttons.wait_for([B.KEY_RIGHT]) + + return Path.MAIN_MENU + + ### Store a seed (temp) Menu + + def show_store_a_seed_tool(self): + seed_phrase = [] + ret_val = 0 + ret_val = self.menu_view.display_saved_seed_menu(self.storage, 1, "... [ Return to Seed Tools ]") + if ret_val == 0: + return Path.SEED_TOOLS_SUB_MENU + + slot_num = ret_val + + if self.storage.check_slot(slot_num) == True: + # show seed phrase + # display seed phrase (24 words) + while True: + r = self.seed_tools_view.display_seed_phrase(self.storage.get_seed_phrase(abs(slot_num)), "Right to Continue") + if r == True: + break + return Path.MAIN_MENU + else: + # display menu to select 12 or 24 word seed for last word + ret_val = self.menu_view.display_12_24_word_menu("... [ Return to Seed Tools ]") + if ret_val == Path.SEED_WORD_12: + seed_phrase = self.seed_tools_view.display_gather_words_screen(12) + elif ret_val == Path.SEED_WORD_24: + seed_phrase = self.seed_tools_view.display_gather_words_screen(24) + else: + return Path.SEED_TOOLS_SUB_MENU + + if len(seed_phrase) == 0: + return Path.SEED_TOOLS_SUB_MENU + + self.menu_view.draw_modal(["Validating ..."]) + is_valid = self.storage.check_if_seed_valid(seed_phrase) + if is_valid: + self.storage.save_seed_phrase(seed_phrase, slot_num) + self.menu_view.draw_modal(["Seed Valid", "Saved to Slot #" + str(slot_num)], "", "Right to Continue") + input = self.buttons.wait_for([B.KEY_RIGHT]) + else: + self.menu_view.draw_modal(["Seed Invalid", "check seed phrase", "and try again"], "", "Right to Continue") + input = self.buttons.wait_for([B.KEY_RIGHT]) + + return Path.MAIN_MENU + + + ### + ### Signing Tools Navigation/Launcher + ### + + ### Generate XPUB + + def show_generate_xpub(self): + seed_phrase = [] + + # If there is a saved seed, ask to use saved seed + if self.storage.num_of_saved_seeds() > 0: + r = self.menu_view.display_generic_selection_menu(["Yes", "No"], "Use Save Seed?") + if r == 1: #Yes + slot_num = self.menu_view.display_saved_seed_menu(self.storage,3,None) + if slot_num not in (1,2,3): + return Path.SIGNING_TOOLS_SUB_MENU + seed_phrase = self.storage.get_seed_phrase(slot_num) + + if len(seed_phrase) == 0: + # gather seed phrase + # display menu to select 12 or 24 word seed for last word + ret_val = self.menu_view.display_12_24_word_menu("... [ Return to Sign Tools ]") + if ret_val == Path.SEED_WORD_12: + seed_phrase = self.seed_tools_view.display_gather_words_screen(12) + elif ret_val == Path.SEED_WORD_24: + seed_phrase = self.seed_tools_view.display_gather_words_screen(24) + else: + return Path.SIGNING_TOOLS_SUB_MENU + + if len(seed_phrase) == 0: + return Path.SIGNING_TOOLS_SUB_MENU + + # check if seed phrase is valid + self.menu_view.draw_modal(["Validating ..."]) + is_valid = self.storage.check_if_seed_valid(seed_phrase) + if is_valid == False: + self.menu_view.draw_modal(["Seed Invalid", "check seed phrase", "and try again"], "", "Right to Continue") + input = self.buttons.wait_for([B.KEY_RIGHT]) + return Path.MAIN_MENU + + # display seed phrase + while True: + r = self.seed_tools_view.display_seed_phrase(seed_phrase, "Right to See QR") + if r == True: + break + + self.signing_tools_view.display_xpub_qr(seed_phrase) + time.sleep(1) + input = self.buttons.wait_for([B.KEY_RIGHT]) + return Path.MAIN_MENU + + ### Sign Transactions + + def show_sign_transaction(self): + seed_phrase = [] + + # If there is a saved seed, ask to use saved seed + if self.storage.num_of_saved_seeds() > 0: + r = self.menu_view.display_generic_selection_menu(["Yes", "No"], "Use Save Seed?") + if r == 1: #Yes + slot_num = self.menu_view.display_saved_seed_menu(self.storage,3,None) + if slot_num == 0: + return Path.SIGNING_TOOLS_SUB_MENU + seed_phrase = self.storage.get_seed_phrase(slot_num) + + if len(seed_phrase) == 0: + # gather seed phrase + # display menu to select 12 or 24 word seed for last word + ret_val = self.menu_view.display_12_24_word_menu("... [ Return to Sign Tools ]") + if ret_val == Path.SEED_WORD_12: + seed_phrase = self.seed_tools_view.display_gather_words_screen(12) + elif ret_val == Path.SEED_WORD_24: + seed_phrase = self.seed_tools_view.display_gather_words_screen(24) + else: + return Path.SIGNING_TOOLS_SUB_MENU + + if len(seed_phrase) == 0: + return Path.SIGNING_TOOLS_SUB_MENU + + # check if seed phrase is valid + self.menu_view.draw_modal(["Validating ..."]) + is_valid = self.storage.check_if_seed_valid(seed_phrase) + if is_valid == False: + self.menu_view.draw_modal(["Seed Invalid", "check seed phrase", "and try again"], "", "Right to Continue") + input = self.buttons.wait_for([B.KEY_RIGHT]) + return Path.MAIN_MENU + + # display seed phrase + while True: + r = self.seed_tools_view.display_seed_phrase(seed_phrase, "Right to Scan QR") + if r == True: + break + else: + return Path.SIGNING_TOOLS_SUB_MENU + + # Scan PSBT Animated QR using Camera + self.menu_view.draw_modal(["Loading..."]) + signer = PSBTSigner(seed_phrase, self) + raw_pbst = signer.scan_animated_psbt_qr() + print("raw_pbst: " + raw_pbst) + if raw_pbst == "nodata": + return Path.SIGNING_TOOLS_SUB_MENU + if raw_pbst == "invalid": + self.menu_view.draw_modal(["QR Format Unexpected"], "", "RIGHT to EXIT") + input = self.buttons.wait_for([B.KEY_RIGHT]) + return Path.SIGNING_TOOLS_SUB_MENU + self.menu_view.draw_modal(["Parsing PSBT ..."]) + signer.parse_psbt(raw_pbst) + + # show transaction information before sign + self.signing_tools_view.display_transaction_information(signer) + input = self.buttons.wait_for([B.KEY_RIGHT, B.KEY_LEFT], False) + if input == B.KEY_LEFT: + return Path.SIGNING_TOOLS_SUB_MENU + + # Sign PSBT + self.menu_view.draw_modal(["PSBT Signing ..."]) + (status, signed_pbst) = signer.sign_transaction() + + # Display Animated QR Code + self.signing_tools_view.display_signed_psbt_animated_qr(signed_pbst) + + # Return to Main Menu + return Path.MAIN_MENU + + + ### + ### Settings Tools Navigation/Launcher + ### + + #### Show IO Test + + def show_io_test_tool(self): + ret_val = True + + ret_val = self.io_test_view.display_io_test_screen() + + if ret_val == True: + return Path.MAIN_MENU + + ### Show Current Network + + def show_current_network_tool(self): + r = self.settings_tools_view.display_current_network() + if r == "main": + self.storage.set_network("main") + self.storage.set_hardened_derivation("m/48h/0h/0h/2h") + elif r == "test": + self.storage.set_network("test") + self.storage.set_hardened_derivation("m/48h/1h/0h/2h") + + return Path.SETTINGS_SUB_MENU + + ### Show Wallet Selection Tool + + def show_wallet_tool(self): + r = self.settings_tools_view.display_wallet_selection() + if r == "Specter Desktop": + pass + + return Path.SETTINGS_SUB_MENU + + ### Show Version Info + + def show_version_info(self): + self.settings_tools_view.display_version_info() + input = self.buttons.wait_for([B.KEY_LEFT, B.KEY_RIGHT]) + if input == B.KEY_LEFT: + return Path.SETTINGS_SUB_MENU + elif input == B.KEY_RIGHT: + return Path.MAIN_MENU + + ### Show Donate Screen and QR + + def show_donate_tool(self): + self.settings_tools_view.display_donate_info_screen() + + input = self.buttons.wait_for([B.KEY_LEFT, B.KEY_RIGHT]) + if input == B.KEY_LEFT: + return Path.SETTINGS_SUB_MENU + elif input == B.KEY_RIGHT: + self.settings_tools_view.display_donate_qr() + time.sleep(1) + input = self.buttons.wait_for([B.KEY_RIGHT]) + return Path.MAIN_MENU + diff --git a/ST7789.py b/helpers/ST7789.py similarity index 96% rename from ST7789.py rename to helpers/ST7789.py index 0edd1d12..8f8de657 100644 --- a/ST7789.py +++ b/helpers/ST7789.py @@ -3,7 +3,6 @@ import RPi.GPIO as GPIO import time import numpy as np - class ST7789(object): """class for ST7789 240*240 1.3inch OLED displays.""" diff --git a/helpers/buttons.py b/helpers/buttons.py new file mode 100644 index 00000000..b79d3453 --- /dev/null +++ b/helpers/buttons.py @@ -0,0 +1,82 @@ +import RPi.GPIO as GPIO +import time + +class Buttons: + + KEY_UP_PIN = 6 + KEY_DOWN_PIN = 19 + KEY_LEFT_PIN = 5 + KEY_RIGHT_PIN = 26 + KEY_PRESS_PIN = 13 + + KEY1_PIN = 21 + KEY2_PIN = 20 + KEY3_PIN = 16 + + def __init__(self) -> None: + #init GPIO + GPIO.setmode(GPIO.BCM) + GPIO.setup(Buttons.KEY_UP_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Input with pull-up + GPIO.setup(Buttons.KEY_DOWN_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Input with pull-up + GPIO.setup(Buttons.KEY_LEFT_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Input with pull-up + GPIO.setup(Buttons.KEY_RIGHT_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Input with pull-up + GPIO.setup(Buttons.KEY_PRESS_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Input with pull-up + GPIO.setup(Buttons.KEY1_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Input with pull-up + GPIO.setup(Buttons.KEY2_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Input with pull-up + GPIO.setup(Buttons.KEY3_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Input with pull-up + + self.GPIO = GPIO + self.override_ind = False + + self.add_events([B.KEY_UP, B.KEY_DOWN, B.KEY_PRESS, B.KEY_LEFT, B.KEY_RIGHT, B.KEY1, B.KEY2, B.KEY3]) + + return + + def wait_for(self, keys = [], check_release = True) -> int: + while True: + for i in keys: + if check_release == False or (check_release == True and B.release_lock == True): + # when check release is False or the release lock is released (True) + if self.GPIO.input(i) == GPIO.LOW or self.override_ind == True: + B.release_lock = False + if self.override_ind == True: + self.override_ind = False + return B.OVERRIDE + return i + time.sleep(0.01) # wait 10 ms to give CPU chance to do other things + + def add_events(self, keys = []): + for i in keys: + GPIO.add_event_detect(i, self.GPIO.RISING, callback=Buttons.rising_callback) + + def rising_callback(channel): + B.release_lock = True + return + + def trigger_override(self) -> bool: + if self.override_ind == False: + self.override_ind = True + return True + + return False + + def check_for_low(self, key) -> bool: + if self.GPIO.input(key) == self.GPIO.LOW: + return True + return False + +# class used as short hand for static button/channel lookup values + +class B: + + KEY_UP = 6 + KEY_DOWN = 19 + KEY_LEFT = 5 + KEY_RIGHT = 26 + KEY_PRESS = 13 + KEY1 = 21 + KEY2 = 20 + KEY3 = 16 + OVERRIDE = 1000 + + release_lock = True # released when True, locked when False diff --git a/helpers/camera_process.py b/helpers/camera_process.py new file mode 100644 index 00000000..8cd82679 --- /dev/null +++ b/helpers/camera_process.py @@ -0,0 +1,80 @@ +# External Dependencies +from multiprocessing import Queue +from threading import Timer +import time + +class CameraProcess: + + def start(out_queue, in_queue): + + print("CameraProcess start") + + from imutils.video import VideoStream + from pyzbar import pyzbar + + print("CameraProcess finish import") + + running = True + + while running == True: + + camera_on = False + + msg = [] + msg = in_queue.get() + + if msg[0] == "start": + print("start camera!!") + vs = VideoStream(usePiCamera=True,resolution=(512, 384),framerate=12).start() # For Pi Camera + time.sleep(2.0) + + msg[0] = "" + camera_on = True + + while camera_on: + frame = vs.read() + barcodes = pyzbar.decode(frame) + for barcode in barcodes: + data = barcode.data.decode("utf-8") + out_queue.put([data]) + break + if len(barcodes) == 0: + out_queue.put(["nodata"]) + + try: + msg = in_queue.get(False) + except: + pass + + if msg[0] == "stop": + vs.stop() + camera_on = False + + elif msg[0] == "stop": + print("stop camera!!") + +class CameraPoll(object): + + def __init__(self, interval, function, *args, **kwargs): + self._timer = None + self.interval = interval + self.function = function + self.args = args + self.kwargs = kwargs + self.is_running = False + self.start() + + def _run(self): + self.is_running = False + self.start() + self.function(*self.args, **self.kwargs) + + def start(self): + if not self.is_running: + self._timer = Timer(self.interval, self._run) + self._timer.start() + self.is_running = True + + def stop(self): + self._timer.cancel() + self.is_running = False \ No newline at end of file diff --git a/helpers/path.py b/helpers/path.py new file mode 100644 index 00000000..68e183ac --- /dev/null +++ b/helpers/path.py @@ -0,0 +1,29 @@ +# Static Consents used globally to route to different parts of the app making it easier to read + +class Path: + + # Menu Location Routes + MAIN_MENU = 0 + SEED_TOOLS_SUB_MENU = 10 + SIGNING_TOOLS_SUB_MENU = 11 + SETTINGS_SUB_MENU = 12 + SEED_WORD_12 = 20 + SEED_WORD_24 = 21 + POWER_OFF = 22 + + # Tools / Functions Routes + GEN_LAST_WORD = 40 + DICE_GEN_SEED = 41 + SAVE_SEED = 42 + GEN_XPUB = 50 + SIGN_TRANSACTION = 51 + IO_TEST_TOOL = 60 + CURRENT_NETWORK = 61 + VERSION_INFO = 62 + DONATE = 63 + WALLET = 64 + + # Seed Slots + SEED_SLOT_1 = 80 + SEED_SLOT_2 = 81 + SEED_SLOT_3 = 82 \ No newline at end of file diff --git a/helpers/psbt_signer.py b/helpers/psbt_signer.py new file mode 100644 index 00000000..05a99922 --- /dev/null +++ b/helpers/psbt_signer.py @@ -0,0 +1,331 @@ +from buttons import Buttons, B +from camera_process import CameraProcess +from seed_storage import SeedStorage +from camera_process import CameraPoll +from view import View + +# External Dependencies +from embit.bip39 import mnemonic_to_bytes +from embit.bip39 import mnemonic_from_bytes +from embit import bip39 +from embit import script +from embit import bip32 +from embit import psbt +from embit.networks import NETWORKS +from embit import ec +import time +import threading +from threading import Timer +import re +from io import BytesIO +from binascii import unhexlify, hexlify, a2b_base64, b2a_base64 +import textwrap + +class PSBTSigner(): + + def __init__(self, seed_phrase, controller) -> None: + + # check if seed is valid + try: + seed = bip39.mnemonic_to_seed((" ".join(seed_phrase)).strip()) + except ValueError: + return + + self.controller = controller + self.seed_storage = controller.storage + self.buttons = controller.buttons + + self.seed = seed + self.root = bip32.HDKey.from_seed(self.seed, version=NETWORKS[self.seed_storage.get_network()]["xprv"]) + self.fingerprint = self.root.child(0).fingerprint + self.bip48_xprv = self.root.derive(self.seed_storage.get_hardened_derivation()) + self.bip48_xpub = self.bip48_xprv.to_public() + self.seed_phrase = seed_phrase + + self.tx = None + self.inp_amount = None + self.fee = None + self.spend = None + self.destinationaddress = None + self.raw_psbt = None + + self.camera_loop_timer = None + self.camera_data = None + self.is_camera_data = False + + self.qr_total_frames = 0 + self.qr_cur_frame_count = 0 + self.qr_data = [] + self.frame_display = [] + self.percentage_complete = 0 + + self.scan_started_ind = 0 + + return + + def parse_psbt(self, raw_psbt) -> bool: + # Parse pbst transaction + #try: + base64_psbt = a2b_base64(raw_psbt) + tx = psbt.PSBT.parse(base64_psbt) + #except: + # return False + + self.tx = tx + (self.inp_amount, policy) = PSBTSigner.input_amount(self.tx) + (self.change, self.fee, self.spend, self.destinationaddress) = PSBTSigner.change_fee_spend_amounts(self.tx, self.inp_amount, policy, self.seed_storage.get_network()) + self.raw_psbt = raw_psbt + + return True + + def sign_transaction(self) -> (bool, str): + + # try: + # sign the transaction + self.tx.sign_with(self.root) + + #added section to trim psbt + trimmed_psbt = psbt.PSBT(self.tx.tx) + sigsEnd = 0 + for i, inp in enumerate(self.tx.inputs): + sigsEnd += len(list(inp.partial_sigs.keys())) + trimmed_psbt.inputs[i].partial_sigs = inp.partial_sigs + + raw_trimmed_signed_psbt = trimmed_psbt.serialize() + # except: + # return (False, self.tx) + + # convert to base64 + b64_psbt = b2a_base64(raw_trimmed_signed_psbt) + # somehow b2a ends with \n... + if b64_psbt[-1:] == b"\n": + b64_psbt = b64_psbt[:-1] + + return (True, b64_psbt.decode('utf-8')) + + def scan_animated_psbt_qr(self) -> str: + self.controller.menu_view.draw_modal(["Initializing Camera"]) + # initialize camera + self.controller.to_camera_queue.put(["start"]) + # First get blocking, this way it's clear when the camera is ready for the end user + self.controller.from_camera_queue.get() + self.camera_loop_timer = CameraPoll(0.05, self.process_camera_data) + + input = self.buttons.wait_for([B.KEY_LEFT, B.KEY_RIGHT]) + if input in (B.KEY_LEFT, B.KEY_RIGHT): + self.camera_loop_timer.stop() + self.controller.to_camera_queue.put(["stop"]) + return "nodata" + elif input == B.OVERRIDE: + self.camera_loop_timer.stop() + self.controller.to_camera_queue.put(["stop"]) + if self.qr_data[0] == "invalid": + return "invalid" + return "".join(self.qr_data) + + def process_camera_data(self): + try: + data = self.controller.from_camera_queue.get(False) + except: + data = ["nodata"] + + if data[0] != "nodata": + if self.qr_total_frames == 0: + self.qr_total_frames = self.get_totals_frames(data[0]) + if self.qr_total_frames == -1: + self.qr_data = ["invalid"] + self.buttons.trigger_override() # something went wrong, invalid QR + return + self.qr_data = ["empty"] * self.qr_total_frames + self.frame_display = ["-"] * self.qr_total_frames + current_frame = self.get_current_frame(data[0]) + if self.qr_data[current_frame - 1] == "empty": + self.qr_data[current_frame - 1] = self.parse_qr_data(data[0]) + self.qr_cur_frame_count += 1 + self.frame_display[current_frame - 1] = "*" + if self.qr_total_frames > 0: + self.percentage_complete = int((self.qr_cur_frame_count / self.qr_total_frames) * 100) + if "empty" not in self.qr_data: + # pulled all animated qr frames + self.buttons.trigger_override() + + + #self.frame_display = [f.replace('x', '*') for f in self.frame_display] + #self.frame_display[current_frame - 1] = "x" + + # display percentage / frames complete + print(self.frame_display) + + if "empty" in self.qr_data: + View.draw.rectangle((0, 0, View.canvas_width, View.canvas_height), outline=0, fill=0) + tw, th = View.draw.textsize("Collecting QR Codes:", font=View.IMPACT22) + View.draw.text(((240 - tw) / 2, 15), "Collecting QR Codes:", fill="ORANGE", font=View.IMPACT22) + lines = textwrap.wrap("".join(self.frame_display), width=11) + yheight = 60 + for line in lines: + tw, th = View.draw.textsize(line, font=View.COURIERNEW30) + View.draw.text(((240 - tw) / 2, yheight), line, fill="ORANGE", font=View.COURIERNEW30) + yheight += 30 + tw, th = View.draw.textsize("Right to Exit", font=View.IMPACT18) + View.draw.text(((240 - tw) / 2, 215), "Right to Exit", fill="ORANGE", font=View.IMPACT18) + View.DispShowImage() + + elif self.scan_started_ind == 0: + self.scan_started_ind = 1 + self.controller.menu_view.draw_modal(["Scan Animated QR"], "", "Right to Exit") + + def get_totals_frames(self, camera_data) -> int: + if re.search("^p(\d+)of(\d+) ", camera_data, re.IGNORECASE) != None: + return int(re.search("^p(\d+)of(\d+) ", camera_data, re.IGNORECASE).group(2)) + else: + return -1 + + def get_current_frame(self, camera_data) -> int: + if re.search("^p(\d+)of(\d+) ", camera_data, re.IGNORECASE) != None: + return int(re.search("^p(\d+)of(\d+) ", camera_data, re.IGNORECASE).group(1)) + else: + return -1 + + def parse_qr_data(self, camera_data) -> str: + return camera_data.split(" ")[-1].strip() + + ### + ### Internal PSBTSigner Transactions + ### + + def input_amount(tx) -> (float, str): + # Check inputs of the transaction and check that they use the same script type + # For multisig parsed policy will look like this: + # { script_type: p2wsh, cosigners: [xpubs strings], m: 2, n: 3} + policy = None + inp_amount = 0.0 + for inp in tx.inputs: + inp_amount += inp.witness_utxo.value + # get policy of the input + inp_policy = PSBTSigner.get_policy(inp, inp.witness_utxo.script_pubkey, tx.xpubs) + # if policy is None - assign current + if policy is None: + policy = inp_policy + # otherwise check that everything in the policy is the same + else: + # check policy is the same + if policy != inp_policy: + raise RuntimeError("Mixed inputs in the transaction") + + return (inp_amount, policy) + + def change_fee_spend_amounts(tx, inp_amount, policy, currentnetwork) -> (float, float, float): + spend = 0 + change = 0 + for i, out in enumerate(tx.outputs): + out_policy = PSBTSigner.get_policy(out, tx.tx.vout[i].script_pubkey, tx.xpubs) + is_change = False + # if policy is the same - probably change + if out_policy == policy: + # double-check that it's change + # we already checked in get_cosigners and parse_multisig + # that pubkeys are generated from cosigners, + # and witness script is corresponding multisig + # so we only need to check that scriptpubkey is generated from + # witness script + + # empty script by default + sc = script.Script(b"") + # multisig, we know witness script + if policy["type"] == "p2wsh": + sc = script.p2wsh(out.witness_script) + elif policy["type"] == "p2sh-p2wsh": + sc = script.p2sh(script.p2wsh(out.witness_script)) + # single-sig + elif "pkh" in policy["type"]: + if len(out.bip32_derivations.values()) > 0: + der = list(out.bip32_derivations.values())[0].derivation + my_pubkey = root.derive(der) + if policy["type"] == "p2wpkh": + sc = script.p2wpkh(my_pubkey) + elif policy["type"] == "p2sh-p2wpkh": + sc = script.p2sh(script.p2wpkh(my_pubkey)) + if sc.data == tx.tx.vout[i].script_pubkey.data: + is_change = True + if is_change: + change += tx.tx.vout[i].value + print("Change %d sats" % tx.tx.vout[i].value) + else: + spend += tx.tx.vout[i].value + print("Spending %d sats to %s" % (tx.tx.vout[i].value, tx.tx.vout[i].script_pubkey.address(NETWORKS[currentnetwork]))) + destinationaddress = tx.tx.vout[i].script_pubkey.address(NETWORKS[currentnetwork]) + + fee = inp_amount - change - spend + + return (change, fee, spend, destinationaddress) + + def parse_multisig(sc): + """Takes a script and extracts m,n and pubkeys from it""" + # OP_m ... OP_n OP_CHECKMULTISIG + # check min size + if len(sc.data) < 37 or sc.data[-1] != 0xae: + raise ValueError("Not a multisig script") + m = sc.data[0] - 0x50 + if m < 1 or m > 16: + raise ValueError("Invalid multisig script") + n = sc.data[-2] - 0x50 + if n < m or n > 16: + raise ValueError("Invalid multisig script") + s = BytesIO(sc.data) + # drop first byte + s.read(1) + # read pubkeys + pubkeys = [] + for i in range(n): + char = s.read(1) + if char != b"\x21": + raise ValueError("Invlid pubkey") + pubkeys.append(ec.PublicKey.parse(s.read(33))) + # check that nothing left + if s.read() != sc.data[-2:]: + raise ValueError("Invalid multisig script") + return m, n, pubkeys + + def get_cosigners(pubkeys, derivations, xpubs): + """Returns xpubs used to derive pubkeys using global xpub field from psbt""" + cosigners = [] + for i, pubkey in enumerate(pubkeys): + if pubkey not in derivations: + raise ValueError("Missing derivation") + der = derivations[pubkey] + for xpub in xpubs: + origin_der = xpubs[xpub] + # check fingerprint + if origin_der.fingerprint == der.fingerprint: + # check derivation - last two indexes give pub from xpub + if origin_der.derivation == der.derivation[:-2]: + # check that it derives to pubkey actually + if xpub.derive(der.derivation[-2:]).key == pubkey: + # append strings so they can be sorted and compared + cosigners.append(xpub.to_base58()) + break + if len(cosigners) != len(pubkeys): + raise RuntimeError("Can't get all cosigners") + return sorted(cosigners) + + def get_policy(scope, scriptpubkey, xpubs): + """Parse scope and get policy""" + # we don't know the policy yet, let's parse it + script_type = scriptpubkey.script_type() + # p2sh can be either legacy multisig, or nested segwit multisig + # or nested segwit singlesig + if script_type == "p2sh": + if scope.witness_script is not None: + script_type = "p2sh-p2wsh" + elif scope.redeem_script is not None and scope.redeem_script.script_type() == "p2wpkh": + script_type = "p2sh-p2wpkh" + policy = { "type": script_type } + # expected multisig + if "p2wsh" in script_type and scope.witness_script is not None: + m, n, pubkeys = PSBTSigner.parse_multisig(scope.witness_script) + # check pubkeys are derived from cosigners + cosigners = PSBTSigner.get_cosigners(pubkeys, scope.bip32_derivations, xpubs) + policy.update({ + "m": m, "n": n, "cosigners": cosigners + }) + return policy \ No newline at end of file diff --git a/helpers/qr.py b/helpers/qr.py new file mode 100644 index 00000000..26db92a3 --- /dev/null +++ b/helpers/qr.py @@ -0,0 +1,49 @@ +import qrcode + +class QR: + + def __init__(self) -> None: + self.qrsize = 120 # Default + + def qrimage(self, data, qrsize = 0): + if qrsize != 0: + self.qrsize = qrsize + + qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=1, border=2 ) + qr.add_data(data) + qr.make(fit=True) + return(qr.make_image(fill_color="black", back_color="white").resize((240,240)).convert('RGB')) + + def makeqrcodes(self, data, format, qrsize = 0, callback = None) -> []: + if qrsize != 0: + self.qrsize = qrsize + + cnt = 0 + qr_cnt = 0 + start = 0 + stop = self.qrsize + data_parts = [] + images = [] + + if format == "Specter Desktop": + + qr_cnt = (len(data) // self.qrsize) + 1 + + if qr_cnt == 1: + return [self.qrimage(data)] + else: + while cnt < qr_cnt: + + data_parts.append("p" + str(cnt+1) + "of" + str(qr_cnt) + " " + data[start:stop]) + images.append(self.qrimage(data_parts[-1], qrsize)) + print(data_parts[-1]) + start = start + self.qrsize + stop = stop + self.qrsize + if stop > len(data): + stop = len(data) + cnt += 1 + + if callback != None: + callback((cnt * 100.0) / qr_cnt) + + return images \ No newline at end of file diff --git a/main.py b/main.py index 8004a0ac..3b1f387d 100644 --- a/main.py +++ b/main.py @@ -1,44 +1,12 @@ -import resources +import sys +sys.path.append('./views') +sys.path.append('./models') +sys.path.append('./helpers') -runstate = [0, "", ["", "", ""]] -seedsignerrunning = True +from controller import Controller +import time -while seedsignerrunning == True: - if runstate[0] == 0: - resources.main_menu(runstate) - if runstate[0] == 1: - resources.seedgen_menu(runstate) - if runstate[0] == 2: - resources.signing_menu(runstate) - if runstate[0] == 3: - resources.settings_menu(runstate) - if runstate[0] == 50: - resources.iotestscreen(runstate) - if runstate[0] == 51: - resources.get_pre_calc_words(runstate) - if runstate[0] == 52: - resources.get_final_word(runstate) - if runstate[0] == 53: - resources.getseedfromdice(runstate) - if runstate[0] == 54: - resources.make_xpub(runstate) - if runstate[0] == 55: - resources.sign_psbt(runstate) - if runstate[0] == 56: - resources.donate(runstate) - if runstate[0] == 57: - resources.version_info(runstate) - if runstate[0] == 58: - resources.powering_down_notifier(runstate) - if runstate[0] == 59: - resources.gather_23_words(runstate) - if runstate[0] == 60: - resources.gather_11_words(runstate) - if runstate[0] == 61: - resources.network_menu(runstate) - if runstate[0] == 62: - resources.seedselect_menu(runstate) - if runstate[0] == 63: - resources.tempsaveseed(runstate) - print("Back at main and runstate is:") - print(runstate) +DEBUG = True + +controller = Controller() +controller.start(DEBUG) \ No newline at end of file diff --git a/models/seed_storage.py b/models/seed_storage.py new file mode 100644 index 00000000..25a0856d --- /dev/null +++ b/models/seed_storage.py @@ -0,0 +1,144 @@ +# External Dependencies +from embit.bip39 import mnemonic_to_bytes +from embit.bip39 import mnemonic_from_bytes +from embit import bip39 + +class SeedStorage: + + SEEDWORDS = ["abandon", "ability", "able", "about", "above", "absent", "absorb", "abstract", "absurd", "abuse", "access", "accident", "account", "accuse", "achieve", "acid", "acoustic", "acquire", "across", "act", "action", "actor", "actress", "actual", "adapt", "add", "addict", "address", "adjust", "admit", "adult", "advance", "advice", "aerobic", "affair", "afford", "afraid", "again", "age", "agent", "agree", "ahead", "aim", "air", "airport", "aisle", "alarm", "album", "alcohol", "alert", "alien", "all", "alley", "allow", "almost", "alone", "alpha", "already", "also", "alter", "always", "amateur", "amazing", "among", "amount", "amused", "analyst", "anchor", "ancient", "anger", "angle", "angry", "animal", "ankle", "announce", "annual", "another", "answer", "antenna", "antique", "anxiety", "any", "apart", "apology", "appear", "apple", "approve", "april", "arch", "arctic", "area", "arena", "argue", "arm", "armed", "armor", "army", "around", "arrange", "arrest", "arrive", "arrow", "art", "artefact", "artist", "artwork", "ask", "aspect", "assault", "asset", "assist", "assume", "asthma", "athlete", "atom", "attack", "attend", "attitude", "attract", "auction", "audit", "august", "aunt", "author", "auto", "autumn", "average", "avocado", "avoid", "awake", "aware", "away", "awesome", "awful", "awkward", "axis", "baby", "bachelor", "bacon", "badge", "bag", "balance", "balcony", "ball", "bamboo", "banana", "banner", "bar", "barely", "bargain", "barrel", "base", "basic", "basket", "battle", "beach", "bean", "beauty", "because", "become", "beef", "before", "begin", "behave", "behind", "believe", "below", "belt", "bench", "benefit", "best", "betray", "better", "between", "beyond", "bicycle", "bid", "bike", "bind", "biology", "bird", "birth", "bitter", "black", "blade", "blame", "blanket", "blast", "bleak", "bless", "blind", "blood", "blossom", "blouse", "blue", "blur", "blush", "board", "boat", "body", "boil", "bomb", "bone", "bonus", "book", "boost", "border", "boring", "borrow", "boss", "bottom", "bounce", "box", "boy", "bracket", "brain", "brand", "brass", "brave", "bread", "breeze", "brick", "bridge", "brief", "bright", "bring", "brisk", "broccoli", "broken", "bronze", "broom", "brother", "brown", "brush", "bubble", "buddy", "budget", "buffalo", "build", "bulb", "bulk", "bullet", "bundle", "bunker", "burden", "burger", "burst", "bus", "business", "busy", "butter", "buyer", "buzz", "cabbage", "cabin", "cable", "cactus", "cage", "cake", "call", "calm", "camera", "camp", "can", "canal", "cancel", "candy", "cannon", "canoe", "canvas", "canyon", "capable", "capital", "captain", "car", "carbon", "card", "cargo", "carpet", "carry", "cart", "case", "cash", "casino", "castle", "casual", "cat", "catalog", "catch", "category", "cattle", "caught", "cause", "caution", "cave", "ceiling", "celery", "cement", "census", "century", "cereal", "certain", "chair", "chalk", "champion", "change", "chaos", "chapter", "charge", "chase", "chat", "cheap", "check", "cheese", "chef", "cherry", "chest", "chicken", "chief", "child", "chimney", "choice", "choose", "chronic", "chuckle", "chunk", "churn", "cigar", "cinnamon", "circle", "citizen", "city", "civil", "claim", "clap", "clarify", "claw", "clay", "clean", "clerk", "clever", "click", "client", "cliff", "climb", "clinic", "clip", "clock", "clog", "close", "cloth", "cloud", "clown", "club", "clump", "cluster", "clutch", "coach", "coast", "coconut", "code", "coffee", "coil", "coin", "collect", "color", "column", "combine", "come", "comfort", "comic", "common", "company", "concert", "conduct", "confirm", "congress", "connect", "consider", "control", "convince", "cook", "cool", "copper", "copy", "coral", "core", "corn", "correct", "cost", "cotton", "couch", "country", "couple", "course", "cousin", "cover", "coyote", "crack", "cradle", "craft", "cram", "crane", "crash", "crater", "crawl", "crazy", "cream", "credit", "creek", "crew", "cricket", "crime", "crisp", "critic", "crop", "cross", "crouch", "crowd", "crucial", "cruel", "cruise", "crumble", "crunch", "crush", "cry", "crystal", "cube", "culture", "cup", "cupboard", "curious", "current", "curtain", "curve", "cushion", "custom", "cute", "cycle", "dad", "damage", "damp", "dance", "danger", "daring", "dash", "daughter", "dawn", "day", "deal", "debate", "debris", "decade", "december", "decide", "decline", "decorate", "decrease", "deer", "defense", "define", "defy", "degree", "delay", "deliver", "demand", "demise", "denial", "dentist", "deny", "depart", "depend", "deposit", "depth", "deputy", "derive", "describe", "desert", "design", "desk", "despair", "destroy", "detail", "detect", "develop", "device", "devote", "diagram", "dial", "diamond", "diary", "dice", "diesel", "diet", "differ", "digital", "dignity", "dilemma", "dinner", "dinosaur", "direct", "dirt", "disagree", "discover", "disease", "dish", "dismiss", "disorder", "display", "distance", "divert", "divide", "divorce", "dizzy", "doctor", "document", "dog", "doll", "dolphin", "domain", "donate", "donkey", "donor", "door", "dose", "double", "dove", "draft", "dragon", "drama", "drastic", "draw", "dream", "dress", "drift", "drill", "drink", "drip", "drive", "drop", "drum", "dry", "duck", "dumb", "dune", "during", "dust", "dutch", "duty", "dwarf", "dynamic", "eager", "eagle", "early", "earn", "earth", "easily", "east", "easy", "echo", "ecology", "economy", "edge", "edit", "educate", "effort", "egg", "eight", "either", "elbow", "elder", "electric", "elegant", "element", "elephant", "elevator", "elite", "else", "embark", "embody", "embrace", "emerge", "emotion", "employ", "empower", "empty", "enable", "enact", "end", "endless", "endorse", "enemy", "energy", "enforce", "engage", "engine", "enhance", "enjoy", "enlist", "enough", "enrich", "enroll", "ensure", "enter", "entire", "entry", "envelope", "episode", "equal", "equip", "era", "erase", "erode", "erosion", "error", "erupt", "escape", "essay", "essence", "estate", "eternal", "ethics", "evidence", "evil", "evoke", "evolve", "exact", "example", "excess", "exchange", "excite", "exclude", "excuse", "execute", "exercise", "exhaust", "exhibit", "exile", "exist", "exit", "exotic", "expand", "expect", "expire", "explain", "expose", "express", "extend", "extra", "eye", "eyebrow", "fabric", "face", "faculty", "fade", "faint", "faith", "fall", "false", "fame", "family", "famous", "fan", "fancy", "fantasy", "farm", "fashion", "fat", "fatal", "father", "fatigue", "fault", "favorite", "feature", "february", "federal", "fee", "feed", "feel", "female", "fence", "festival", "fetch", "fever", "few", "fiber", "fiction", "field", "figure", "file", "film", "filter", "final", "find", "fine", "finger", "finish", "fire", "firm", "first", "fiscal", "fish", "fit", "fitness", "fix", "flag", "flame", "flash", "flat", "flavor", "flee", "flight", "flip", "float", "flock", "floor", "flower", "fluid", "flush", "fly", "foam", "focus", "fog", "foil", "fold", "follow", "food", "foot", "force", "forest", "forget", "fork", "fortune", "forum", "forward", "fossil", "foster", "found", "fox", "fragile", "frame", "frequent", "fresh", "friend", "fringe", "frog", "front", "frost", "frown", "frozen", "fruit", "fuel", "fun", "funny", "furnace", "fury", "future", "gadget", "gain", "galaxy", "gallery", "game", "gap", "garage", "garbage", "garden", "garlic", "garment", "gas", "gasp", "gate", "gather", "gauge", "gaze", "general", "genius", "genre", "gentle", "genuine", "gesture", "ghost", "giant", "gift", "giggle", "ginger", "giraffe", "girl", "give", "glad", "glance", "glare", "glass", "glide", "glimpse", "globe", "gloom", "glory", "glove", "glow", "glue", "goat", "goddess", "gold", "good", "goose", "gorilla", "gospel", "gossip", "govern", "gown", "grab", "grace", "grain", "grant", "grape", "grass", "gravity", "great", "green", "grid", "grief", "grit", "grocery", "group", "grow", "grunt", "guard", "guess", "guide", "guilt", "guitar", "gun", "gym", "habit", "hair", "half", "hammer", "hamster", "hand", "happy", "harbor", "hard", "harsh", "harvest", "hat", "have", "hawk", "hazard", "head", "health", "heart", "heavy", "hedgehog", "height", "hello", "helmet", "help", "hen", "hero", "hidden", "high", "hill", "hint", "hip", "hire", "history", "hobby", "hockey", "hold", "hole", "holiday", "hollow", "home", "honey", "hood", "hope", "horn", "horror", "horse", "hospital", "host", "hotel", "hour", "hover", "hub", "huge", "human", "humble", "humor", "hundred", "hungry", "hunt", "hurdle", "hurry", "hurt", "husband", "hybrid", "ice", "icon", "idea", "identify", "idle", "ignore", "ill", "illegal", "illness", "image", "imitate", "immense", "immune", "impact", "impose", "improve", "impulse", "inch", "include", "income", "increase", "index", "indicate", "indoor", "industry", "infant", "inflict", "inform", "inhale", "inherit", "initial", "inject", "injury", "inmate", "inner", "innocent", "input", "inquiry", "insane", "insect", "inside", "inspire", "install", "intact", "interest", "into", "invest", "invite", "involve", "iron", "island", "isolate", "issue", "item", "ivory", "jacket", "jaguar", "jar", "jazz", "jealous", "jeans", "jelly", "jewel", "job", "join", "joke", "journey", "joy", "judge", "juice", "jump", "jungle", "junior", "junk", "just", "kangaroo", "keen", "keep", "ketchup", "key", "kick", "kid", "kidney", "kind", "kingdom", "kiss", "kit", "kitchen", "kite", "kitten", "kiwi", "knee", "knife", "knock", "know", "lab", "label", "labor", "ladder", "lady", "lake", "lamp", "language", "laptop", "large", "later", "latin", "laugh", "laundry", "lava", "law", "lawn", "lawsuit", "layer", "lazy", "leader", "leaf", "learn", "leave", "lecture", "left", "leg", "legal", "legend", "leisure", "lemon", "lend", "length", "lens", "leopard", "lesson", "letter", "level", "liar", "liberty", "library", "license", "life", "lift", "light", "like", "limb", "limit", "link", "lion", "liquid", "list", "little", "live", "lizard", "load", "loan", "lobster", "local", "lock", "logic", "lonely", "long", "loop", "lottery", "loud", "lounge", "love", "loyal", "lucky", "luggage", "lumber", "lunar", "lunch", "luxury", "lyrics", "machine", "mad", "magic", "magnet", "maid", "mail", "main", "major", "make", "mammal", "man", "manage", "mandate", "mango", "mansion", "manual", "maple", "marble", "march", "margin", "marine", "market", "marriage", "mask", "mass", "master", "match", "material", "math", "matrix", "matter", "maximum", "maze", "meadow", "mean", "measure", "meat", "mechanic", "medal", "media", "melody", "melt", "member", "memory", "mention", "menu", "mercy", "merge", "merit", "merry", "mesh", "message", "metal", "method", "middle", "midnight", "milk", "million", "mimic", "mind", "minimum", "minor", "minute", "miracle", "mirror", "misery", "miss", "mistake", "mix", "mixed", "mixture", "mobile", "model", "modify", "mom", "moment", "monitor", "monkey", "monster", "month", "moon", "moral", "more", "morning", "mosquito", "mother", "motion", "motor", "mountain", "mouse", "move", "movie", "much", "muffin", "mule", "multiply", "muscle", "museum", "mushroom", "music", "must", "mutual", "myself", "mystery", "myth", "naive", "name", "napkin", "narrow", "nasty", "nation", "nature", "near", "neck", "need", "negative", "neglect", "neither", "nephew", "nerve", "nest", "net", "network", "neutral", "never", "news", "next", "nice", "night", "noble", "noise", "nominee", "noodle", "normal", "north", "nose", "notable", "note", "nothing", "notice", "novel", "now", "nuclear", "number", "nurse", "nut", "oak", "obey", "object", "oblige", "obscure", "observe", "obtain", "obvious", "occur", "ocean", "october", "odor", "off", "offer", "office", "often", "oil", "okay", "old", "olive", "olympic", "omit", "once", "one", "onion", "online", "only", "open", "opera", "opinion", "oppose", "option", "orange", "orbit", "orchard", "order", "ordinary", "organ", "orient", "original", "orphan", "ostrich", "other", "outdoor", "outer", "output", "outside", "oval", "oven", "over", "own", "owner", "oxygen", "oyster", "ozone", "pact", "paddle", "page", "pair", "palace", "palm", "panda", "panel", "panic", "panther", "paper", "parade", "parent", "park", "parrot", "party", "pass", "patch", "path", "patient", "patrol", "pattern", "pause", "pave", "payment", "peace", "peanut", "pear", "peasant", "pelican", "pen", "penalty", "pencil", "people", "pepper", "perfect", "permit", "person", "pet", "phone", "photo", "phrase", "physical", "piano", "picnic", "picture", "piece", "pig", "pigeon", "pill", "pilot", "pink", "pioneer", "pipe", "pistol", "pitch", "pizza", "place", "planet", "plastic", "plate", "play", "please", "pledge", "pluck", "plug", "plunge", "poem", "poet", "point", "polar", "pole", "police", "pond", "pony", "pool", "popular", "portion", "position", "possible", "post", "potato", "pottery", "poverty", "powder", "power", "practice", "praise", "predict", "prefer", "prepare", "present", "pretty", "prevent", "price", "pride", "primary", "print", "priority", "prison", "private", "prize", "problem", "process", "produce", "profit", "program", "project", "promote", "proof", "property", "prosper", "protect", "proud", "provide", "public", "pudding", "pull", "pulp", "pulse", "pumpkin", "punch", "pupil", "puppy", "purchase", "purity", "purpose", "purse", "push", "put", "puzzle", "pyramid", "quality", "quantum", "quarter", "question", "quick", "quit", "quiz", "quote", "rabbit", "raccoon", "race", "rack", "radar", "radio", "rail", "rain", "raise", "rally", "ramp", "ranch", "random", "range", "rapid", "rare", "rate", "rather", "raven", "raw", "razor", "ready", "real", "reason", "rebel", "rebuild", "recall", "receive", "recipe", "record", "recycle", "reduce", "reflect", "reform", "refuse", "region", "regret", "regular", "reject", "relax", "release", "relief", "rely", "remain", "remember", "remind", "remove", "render", "renew", "rent", "reopen", "repair", "repeat", "replace", "report", "require", "rescue", "resemble", "resist", "resource", "response", "result", "retire", "retreat", "return", "reunion", "reveal", "review", "reward", "rhythm", "rib", "ribbon", "rice", "rich", "ride", "ridge", "rifle", "right", "rigid", "ring", "riot", "ripple", "risk", "ritual", "rival", "river", "road", "roast", "robot", "robust", "rocket", "romance", "roof", "rookie", "room", "rose", "rotate", "rough", "round", "route", "royal", "rubber", "rude", "rug", "rule", "run", "runway", "rural", "sad", "saddle", "sadness", "safe", "sail", "salad", "salmon", "salon", "salt", "salute", "same", "sample", "sand", "satisfy", "satoshi", "sauce", "sausage", "save", "say", "scale", "scan", "scare", "scatter", "scene", "scheme", "school", "science", "scissors", "scorpion", "scout", "scrap", "screen", "script", "scrub", "sea", "search", "season", "seat", "second", "secret", "section", "security", "seed", "seek", "segment", "select", "sell", "seminar", "senior", "sense", "sentence", "series", "service", "session", "settle", "setup", "seven", "shadow", "shaft", "shallow", "share", "shed", "shell", "sheriff", "shield", "shift", "shine", "ship", "shiver", "shock", "shoe", "shoot", "shop", "short", "shoulder", "shove", "shrimp", "shrug", "shuffle", "shy", "sibling", "sick", "side", "siege", "sight", "sign", "silent", "silk", "silly", "silver", "similar", "simple", "since", "sing", "siren", "sister", "situate", "six", "size", "skate", "sketch", "ski", "skill", "skin", "skirt", "skull", "slab", "slam", "sleep", "slender", "slice", "slide", "slight", "slim", "slogan", "slot", "slow", "slush", "small", "smart", "smile", "smoke", "smooth", "snack", "snake", "snap", "sniff", "snow", "soap", "soccer", "social", "sock", "soda", "soft", "solar", "soldier", "solid", "solution", "solve", "someone", "song", "soon", "sorry", "sort", "soul", "sound", "soup", "source", "south", "space", "spare", "spatial", "spawn", "speak", "special", "speed", "spell", "spend", "sphere", "spice", "spider", "spike", "spin", "spirit", "split", "spoil", "sponsor", "spoon", "sport", "spot", "spray", "spread", "spring", "spy", "square", "squeeze", "squirrel", "stable", "stadium", "staff", "stage", "stairs", "stamp", "stand", "start", "state", "stay", "steak", "steel", "stem", "step", "stereo", "stick", "still", "sting", "stock", "stomach", "stone", "stool", "story", "stove", "strategy", "street", "strike", "strong", "struggle", "student", "stuff", "stumble", "style", "subject", "submit", "subway", "success", "such", "sudden", "suffer", "sugar", "suggest", "suit", "summer", "sun", "sunny", "sunset", "super", "supply", "supreme", "sure", "surface", "surge", "surprise", "surround", "survey", "suspect", "sustain", "swallow", "swamp", "swap", "swarm", "swear", "sweet", "swift", "swim", "swing", "switch", "sword", "symbol", "symptom", "syrup", "system", "table", "tackle", "tag", "tail", "talent", "talk", "tank", "tape", "target", "task", "taste", "tattoo", "taxi", "teach", "team", "tell", "ten", "tenant", "tennis", "tent", "term", "test", "text", "thank", "that", "theme", "then", "theory", "there", "they", "thing", "this", "thought", "three", "thrive", "throw", "thumb", "thunder", "ticket", "tide", "tiger", "tilt", "timber", "time", "tiny", "tip", "tired", "tissue", "title", "toast", "tobacco", "today", "toddler", "toe", "together", "toilet", "token", "tomato", "tomorrow", "tone", "tongue", "tonight", "tool", "tooth", "top", "topic", "topple", "torch", "tornado", "tortoise", "toss", "total", "tourist", "toward", "tower", "town", "toy", "track", "trade", "traffic", "tragic", "train", "transfer", "trap", "trash", "travel", "tray", "treat", "tree", "trend", "trial", "tribe", "trick", "trigger", "trim", "trip", "trophy", "trouble", "truck", "true", "truly", "trumpet", "trust", "truth", "try", "tube", "tuition", "tumble", "tuna", "tunnel", "turkey", "turn", "turtle", "twelve", "twenty", "twice", "twin", "twist", "two", "type", "typical", "ugly", "umbrella", "unable", "unaware", "uncle", "uncover", "under", "undo", "unfair", "unfold", "unhappy", "uniform", "unique", "unit", "universe", "unknown", "unlock", "until", "unusual", "unveil", "update", "upgrade", "uphold", "upon", "upper", "upset", "urban", "urge", "usage", "use", "used", "useful", "useless", "usual", "utility", "vacant", "vacuum", "vague", "valid", "valley", "valve", "van", "vanish", "vapor", "various", "vast", "vault", "vehicle", "velvet", "vendor", "venture", "venue", "verb", "verify", "version", "very", "vessel", "veteran", "viable", "vibrant", "vicious", "victory", "video", "view", "village", "vintage", "violin", "virtual", "virus", "visa", "visit", "visual", "vital", "vivid", "vocal", "voice", "void", "volcano", "volume", "vote", "voyage", "wage", "wagon", "wait", "walk", "wall", "walnut", "want", "warfare", "warm", "warrior", "wash", "wasp", "waste", "water", "wave", "way", "wealth", "weapon", "wear", "weasel", "weather", "web", "wedding", "weekend", "weird", "welcome", "west", "wet", "whale", "what", "wheat", "wheel", "when", "where", "whip", "whisper", "wide", "width", "wife", "wild", "will", "win", "window", "wine", "wing", "wink", "winner", "winter", "wire", "wisdom", "wise", "wish", "witness", "wolf", "woman", "wonder", "wood", "wool", "word", "work", "world", "worry", "worth", "wrap", "wreck", "wrestle", "wrist", "write", "wrong", "yard", "year", "ORANGE", "you", "young", "youth", "zebra", "zero", "zone", "zoo"] + + def __init__(self, current_network = "main", hardened_derivation = "m/48h/0h/0h/2h") -> None: + + self.saved_seeds = [[],[],[]] + self.current_network = current_network + self.hardened_derivation = hardened_derivation + + ### + ### Seed Related Methods + ### + + def save_seed_phrase(self, seed_phrase = [], slot_num = 0) -> bool: + slot_idx = slot_num - 1 + if slot_idx in (0,1,2): + self.saved_seeds[slot_idx] = seed_phrase[:] + else: + return False + + def get_seed_phrase(self, slot_num) -> []: + slot_idx = slot_num - 1 + if len(self.saved_seeds[slot_idx]) > 0: + return self.saved_seeds[slot_idx] + else: + return [] + + def valid_seed_structure(self, seed_phrase) -> bool: + if isinstance(seed_phrase, list): + if len(seed_phrase) in (12,24): + if all(word in seed_phrase for word in SEEDWORDS): + return True + else: + return False + else: + return False # Required to be 12 or 24 word seed phrase + else: + return False # Not list, not valid seed_phrase + + def valid_bip39_seed(self, seed_phrase) -> bool: + if self.valid_seed_structure(seed_phrase): + try: + bip39.mnemonic_to_seed((" ".join(seed_phrase)).strip()) + except ValueError: + return False + else: + return False + + return True + + def check_slot_1(self) -> bool: + if len(self.saved_seeds[0]) > 0: + return True + else: + return False + + def check_slot_2(self) -> bool: + if len(self.saved_seeds[1]) > 0: + return True + else: + return False + + def check_slot_3(self) -> bool: + if len(self.saved_seeds[2]) > 0: + return True + else: + return False + + def check_slot(self, slot_num) -> bool: + if len(self.saved_seeds[slot_num-1]) > 0: + return True + else: + return False + + def check_if_seed_valid(self, seed_phrase) -> bool: + try: + bip39.mnemonic_to_seed((" ".join(seed_phrase)).strip()) + except ValueError: + return False + + return True + + def slot_avaliable(self) -> bool: + if len(self.saved_seeds[0]) > 0 and len(self.saved_seeds[1]) > 0 and len(self.saved_seeds[2]) > 0: + return False + return True + + def num_of_saved_seeds(self) -> int: + count = 0 + if len(self.saved_seeds[0]) > 0: + count += 1 + if len(self.saved_seeds[1]) > 0: + count += 1 + if len(self.saved_seeds[2]) > 0: + count += 1 + + return count + + def num_of_free_slots(self) -> int: + count = 0 + if len(self.saved_seeds[0]) == 0: + count += 1 + if len(self.saved_seeds[1]) == 0: + count += 1 + if len(self.saved_seeds[2]) == 0: + count += 1 + + return count + + ### + ### Network Related Methods + ### + + def get_network(self) -> str: + return self.current_network + + def get_hardened_derivation(self) -> str: + return self.hardened_derivation + + def set_network(self, network) -> bool: + if network == "main": + self.current_network = "main" + elif network == "test": + self.current_network = "test" + else: + return False + + return True + + def set_hardened_derivation(self, hardened_derivation) -> bool: + if hardened_derivation == "m/48h/0h/0h/2h": + self.hardened_derivation = "m/48h/0h/0h/2h" + elif hardened_derivation == "m/48h/1h/0h/2h": + self.hardened_derivation = "m/48h/1h/0h/2h" + else: + return False + + return True diff --git a/resources.py b/resources.py deleted file mode 100644 index d4057373..00000000 --- a/resources.py +++ /dev/null @@ -1,3156 +0,0 @@ -import ST7789 -import spidev as SPI -import RPi.GPIO as GPIO - -import time -import subprocess - -from PIL import Image -from PIL import ImageDraw -from PIL import ImageFont - -from subprocess import call - -from imutils.video import VideoStream -from pyzbar import pyzbar -import argparse -import datetime -import imutils -import time -import cv2 - -from embit.bip39 import mnemonic_to_bytes -from embit.bip39 import mnemonic_from_bytes -from embit import script -from embit import bip32 -from embit import bip39 -from embit.networks import NETWORKS -from embit import psbt -from embit import ec - -from io import BytesIO - -from binascii import unhexlify, hexlify, a2b_base64, b2a_base64 - -import qrcode - -import textwrap - -# USE CTL+F to locate the following "modules" -# MENU MODULE -# IO TEST MODULE -# GETWORDS MODULE -# GETLASTWORD MODULE -# DICE MODULE -# XPUBMAKE MODULE -# PSBTSIGN MODULE - -version = "0.3.0" -currentnetwork = "main" -hardened_derivation = "m/48h/0h/0h/2h" - -#GPIO define -RST_PIN = 25 -CS_PIN = 8 -DC_PIN = 24 - -KEY_UP_PIN = 6 -KEY_DOWN_PIN = 19 -KEY_LEFT_PIN = 5 -KEY_RIGHT_PIN = 26 -KEY_PRESS_PIN = 13 - -KEY1_PIN = 21 -KEY2_PIN = 20 -KEY3_PIN = 16 - -RST = 27 -DC = 25 -BL = 24 -bus = 0 -device = 0 - -#init GPIO -GPIO.setmode(GPIO.BCM) -GPIO.setup(KEY_UP_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Input with pull-up -GPIO.setup(KEY_DOWN_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Input with pull-up -GPIO.setup(KEY_LEFT_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Input with pull-up -GPIO.setup(KEY_RIGHT_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Input with pull-up -GPIO.setup(KEY_PRESS_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Input with pull-up -GPIO.setup(KEY1_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Input with pull-up -GPIO.setup(KEY2_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Input with pull-up -GPIO.setup(KEY3_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Input with pull-up - -# 240x240 display with hardware SPI: -disp = ST7789.ST7789(SPI.SpiDev(bus, device),RST, DC, BL) -disp.Init() - -# Create blank image for drawing. -# Make sure to create image with mode '1' for 1-bit color. -width = 240 -height = 240 -image = Image.new('RGB', (width, height)) - -# Get drawing object to draw on image. -draw = ImageDraw.Draw(image) - -# Define necessart fonts -impact16 = ImageFont.truetype('/usr/share/fonts/truetype/msttcorefonts/Impact.ttf', 16) -impact18 = ImageFont.truetype('/usr/share/fonts/truetype/msttcorefonts/Impact.ttf', 18) -impact20 = ImageFont.truetype('/usr/share/fonts/truetype/msttcorefonts/Impact.ttf', 20) -impact22 = ImageFont.truetype('/usr/share/fonts/truetype/msttcorefonts/Impact.ttf', 22) -impact23 = ImageFont.truetype('/usr/share/fonts/truetype/msttcorefonts/Impact.ttf', 23) -impact25 = ImageFont.truetype('/usr/share/fonts/truetype/msttcorefonts/Impact.ttf', 25) -impact26 = ImageFont.truetype('/usr/share/fonts/truetype/msttcorefonts/Impact.ttf', 26) -impact35 = ImageFont.truetype('/usr/share/fonts/truetype/msttcorefonts/Impact.ttf', 35) -impact50 = ImageFont.truetype('/usr/share/fonts/truetype/msttcorefonts/Impact.ttf', 50) -couriernew30 = ImageFont.truetype('/usr/share/fonts/truetype/msttcorefonts/courbd.ttf', 30) - -activeseedsaveslot = 0 -savedseed1status = "[ ]" -savedseed2status = "[ ]" -savedseed3status = "[ ]" - -# BEGIN MENU MODULE -# BEGIN MENU MODULE -# BEGIN MENU MODULE - -def menu_elevator(selected, numoptions): - if GPIO.input(KEY_UP_PIN) == GPIO.LOW: - if selected == 1: - selected = numoptions - time.sleep(0.2) - else: - selected = selected - 1 - time.sleep(0.2) - print("The menu state is: " + str(selected)) - - if GPIO.input(KEY_DOWN_PIN) == GPIO.LOW: - if selected == numoptions: - selected = 1 - time.sleep(0.2) - else: - selected = selected + 1 - time.sleep(0.2) - print("The menu state is: " + str(selected)) - - return selected - -def powering_down_notifier(runstate): - localrunstate = runstate - - draw.rectangle((0, 0, width, height), outline=0, fill=0) - - line1 = "Powering Down..." - line2 = "Please wait about" - line3 = "30 seconds before" - line4 = "disconnecting power." - - textwidth, textheight = draw.textsize(line1, font=impact22) - draw.text(((240-textwidth)/2, 45), line1, fill="ORANGE", font=impact22) - textwidth, textheight = draw.textsize(line2, font=impact20) - draw.text(((240-textwidth)/2, 100), line2, fill="ORANGE", font=impact20) - textwidth, textheight = draw.textsize(line3, font=impact20) - draw.text(((240-textwidth)/2, 130), line3, fill="ORANGE", font=impact20) - textwidth, textheight = draw.textsize(line4, font=impact20) - draw.text(((240-textwidth)/2, 160), line4, fill="ORANGE", font=impact20) - disp.ShowImage(image, 0, 0) - - call("sudo shutdown --poweroff now", shell=True) - -#MAIN MENU FUNCTIONS BELOW -#MAIN MENU FUNCTIONS BELOW -#MAIN MENU FUNCTIONS BELOW - -def main_option1(): - draw.rectangle((0, 0, width, height), outline=0, fill=0) - draw.text((35, 2), "SeedSigner v" + version, fill="ORANGE", font=impact22) - draw.rectangle((5, 40, 210, 75), outline=0, fill="ORANGE") - draw.text((15, 45), "Seed Tools", fill="BLACK", font=impact20) - #draw.rectangle((5, 75, 210, 110), outline=0, fill="ORANGE") - draw.text((15, 80), "Signing Tools", fill="ORANGE", font=impact20) - #draw.rectangle((5, 110, 210, 145), outline=0, fill="ORANGE") - draw.text((15, 115), "Settings", fill="ORANGE", font=impact20) - #draw.rectangle((5, 145, 210, 170), outline=0, fill="ORANGE") - draw.text((15, 150), "Power OFF Device", fill="ORANGE", font=impact20) - draw.text((18, 210), "Press Control Stick to Select", fill="ORANGE", font=impact18) - disp.ShowImage(image, 0, 0) - -def main_option2(): - draw.rectangle((0, 0, width, height), outline=0, fill=0) - draw.text((35, 2), "SeedSigner v" + version, fill="ORANGE", font=impact22) - #draw.rectangle((5, 40, 210, 75), outline=0, fill="ORANGE") - draw.text((15, 45), "Seed Tools", fill="ORANGE", font=impact20) - draw.rectangle((5, 75, 210, 110), outline=0, fill="ORANGE") - draw.text((15, 80), "Signing Tools", fill="BLACK", font=impact20) - #draw.rectangle((5, 110, 210, 145), outline=0, fill="ORANGE") - draw.text((15, 115), "Settings", fill="ORANGE", font=impact20) - #draw.rectangle((5, 145, 210, 170), outline=0, fill="ORANGE") - draw.text((15, 150), "Power OFF Device", fill="ORANGE", font=impact20) - draw.text((18, 210), "Press Control Stick to Select", fill="ORANGE", font=impact18) - disp.ShowImage(image, 0, 0) - -def main_option3(): - draw.rectangle((0, 0, width, height), outline=0, fill=0) - draw.text((35, 2), "SeedSigner v" + version, fill="ORANGE", font=impact22) - #draw.rectangle((5, 40, 210, 75), outline=0, fill="ORANGE") - draw.text((15, 45), "Seed Tools", fill="ORANGE", font=impact20) - #draw.rectangle((5, 75, 210, 110), outline=0, fill="ORANGE") - draw.text((15, 80), "Signing Tools", fill="ORANGE", font=impact20) - draw.rectangle((5, 110, 210, 145), outline=0, fill="ORANGE") - draw.text((15, 115), "Settings", fill="BLACK", font=impact20) - #draw.rectangle((5, 145, 210, 170), outline=0, fill="ORANGE") - draw.text((15, 150), "Power OFF Device", fill="ORANGE", font=impact20) - draw.text((18, 210), "Press Control Stick to Select", fill="ORANGE", font=impact18) - disp.ShowImage(image, 0, 0) - -def main_option4(): - draw.rectangle((0, 0, width, height), outline=0, fill=0) - draw.text((35, 2), "SeedSigner v" + version, fill="ORANGE", font=impact22) - #draw.rectangle((5, 40, 210, 75), outline=0, fill="ORANGE") - draw.text((15, 45), "Seed Tools", fill="ORANGE", font=impact20) - #draw.rectangle((5, 75, 210, 110), outline=0, fill="ORANGE") - draw.text((15, 80), "Signing Tools", fill="ORANGE", font=impact20) - #draw.rectangle((5, 110, 210, 145), outline=0, fill="ORANGE") - draw.text((15, 115), "Settings", fill="ORANGE", font=impact20) - draw.rectangle((5, 145, 210, 180), outline=0, fill="ORANGE") - draw.text((15, 150), "Power OFF Device", fill="BLACK", font=impact20) - draw.text((18, 210), "Press Control Stick to Select", fill="ORANGE", font=impact18) - disp.ShowImage(image, 0, 0) - -def main_menu(runstate): - localrunstate = runstate - running = True - optionselected = 1 - while running == True: - optionselected = menu_elevator(optionselected, 4) - if optionselected == 1: - main_option1() - if optionselected == 2: - main_option2() - if optionselected == 3: - main_option3() - if optionselected == 4: - main_option4() - if GPIO.input(KEY_PRESS_PIN) == GPIO.LOW: - if optionselected == 1: - time.sleep(0.2) - running = False - localrunstate[0] = 1 - return localrunstate - if optionselected == 2: - time.sleep(0.2) - running = False - localrunstate[0] = 2 - return localrunstate - if optionselected == 3: - time.sleep(0.2) - running = False - localrunstate[0] = 3 - return localrunstate - if optionselected == 4: - time.sleep(0.2) - running = False - localrunstate[0] = 58 - #powering_down_notifier() - #call("sudo shutdown --poweroff now", shell=True) - - -# SETTINGS MENU FUNCTIONS BELOW -# SETTINGS MENU FUNCTIONS BELOW -# SETTINGS MENU FUNCTIONS BELOW - -def settings_option1(): - draw.rectangle((0, 0, width, height), outline=0, fill=0) - textwidth, textheight = draw.textsize("Settings (1/2)", font=impact20) - draw.text(((240 - textwidth) / 2, 2), "Settings (1/2)", fill="ORANGE", font=impact20) - draw.rectangle((5, 40, 210, 75), outline=0, fill="ORANGE") - draw.text((15, 45), "... ( return to MAIN )", fill="BLACK", font=impact20) - #draw.rectangle((5, 75, 210, 110), outline=0, fill="ORANGE") - draw.text((15, 80), "Input / Output Tests", fill="ORANGE", font=impact20) - # draw.rectangle((5, 135, 210, 170), outline=0, fill="ORANGE") - draw.text((15, 115), "Current Network: " + currentnetwork, fill="ORANGE", font=impact20) - # draw.rectangle((5, 170, 210, 205), outline=0, fill="ORANGE") - draw.text((15, 150), "Version Info", fill="ORANGE", font=impact20) - # draw.rectangle((5, 170, 210, 205), outline=0, fill="ORANGE") - #draw.text((15, 175), "Donate to SeedSigner", fill="ORANGE", font=impact20) - draw.text((18, 210), "Press Control Stick to Select", fill="ORANGE", font=impact18) - disp.ShowImage(image, 0, 0) - -def settings_option2(): - draw.rectangle((0, 0, width, height), outline=0, fill=0) - textwidth, textheight = draw.textsize("Settings (1/2)", font=impact20) - draw.text(((240 - textwidth) / 2, 2), "Settings (1/2)", fill="ORANGE", font=impact20) - #draw.rectangle((5, 40, 210, 75), outline=0, fill="ORANGE") - draw.text((15, 45), "... ( return to MAIN )", fill="ORANGE", font=impact20) - draw.rectangle((5, 75, 210, 110), outline=0, fill="ORANGE") - draw.text((15, 80), "Input / Output Tests", fill="BLACK", font=impact20) - # draw.rectangle((5, 135, 210, 170), outline=0, fill="ORANGE") - draw.text((15, 115), "Current Network: " + currentnetwork, fill="ORANGE", font=impact20) - # draw.rectangle((5, 170, 210, 205), outline=0, fill="ORANGE") - draw.text((15, 150), "Version Info", fill="ORANGE", font=impact20) - # draw.rectangle((5, 170, 210, 205), outline=0, fill="ORANGE") - # draw.text((15, 175), "Donate to SeedSigner", fill="ORANGE", font=impact20) - draw.text((18, 210), "Press Control Stick to Select", fill="ORANGE", font=impact18) - disp.ShowImage(image, 0, 0) - -def settings_option3(): - draw.rectangle((0, 0, width, height), outline=0, fill=0) - textwidth, textheight = draw.textsize("Settings (1/2)", font=impact20) - draw.text(((240 - textwidth) / 2, 2), "Settings (1/2)", fill="ORANGE", font=impact20) - #draw.rectangle((5, 40, 210, 75), outline=0, fill="ORANGE") - draw.text((15, 45), "... ( return to MAIN )", fill="ORANGE", font=impact20) - # draw.rectangle((5, 75, 210, 110), outline=0, fill="ORANGE") - draw.text((15, 80), "Input / Output Tests", fill="ORANGE", font=impact20) - draw.rectangle((5, 110, 210, 145), outline=0, fill="ORANGE") - draw.text((15, 115), "Current Network: " + currentnetwork, fill="BLACK", font=impact20) - # draw.rectangle((5, 170, 210, 205), outline=0, fill="ORANGE") - draw.text((15, 150), "Version Info", fill="ORANGE", font=impact20) - # draw.rectangle((5, 170, 210, 205), outline=0, fill="ORANGE") - # draw.text((15, 175), "Donate to SeedSigner", fill="ORANGE", font=impact20) - draw.text((18, 210), "Press Control Stick to Select", fill="ORANGE", font=impact18) - disp.ShowImage(image, 0, 0) - -def settings_option4(): - draw.rectangle((0, 0, width, height), outline=0, fill=0) - textwidth, textheight = draw.textsize("Settings (1/2)", font=impact20) - draw.text(((240 - textwidth) / 2, 2), "Settings (1/2)", fill="ORANGE", font=impact20) - #draw.rectangle((5, 40, 210, 75), outline=0, fill="ORANGE") - draw.text((15, 45), "... ( return to MAIN )", fill="ORANGE", font=impact20) - # draw.rectangle((5, 75, 210, 110), outline=0, fill="ORANGE") - draw.text((15, 80), "Input / Output Tests", fill="ORANGE", font=impact20) - # draw.rectangle((5, 135, 210, 170), outline=0, fill="ORANGE") - draw.text((15, 115), "Current Network: " + currentnetwork, fill="ORANGE", font=impact20) - draw.rectangle((5, 145, 210, 180), outline=0, fill="ORANGE") - draw.text((15, 150), "Version Info", fill="BLACK", font=impact20) - # draw.rectangle((5, 170, 210, 205), outline=0, fill="ORANGE") - # draw.text((15, 175), "Donate to SeedSigner", fill="ORANGE", font=impact20) - draw.text((18, 210), "Press Control Stick to Select", fill="ORANGE", font=impact18) - disp.ShowImage(image, 0, 0) - -def settings_option5(): - draw.rectangle((0, 0, width, height), outline=0, fill=0) - textwidth, textheight = draw.textsize("Settings (2/2)", font=impact20) - draw.text(((240 - textwidth) / 2, 2), "Settings (2/2)", fill="ORANGE", font=impact20) - #draw.rectangle((5, 40, 210, 75), outline=0, fill="ORANGE") - #draw.text((15, 45), "... ( return to MAIN )", fill="BLACK", font=impact20) - # draw.rectangle((5, 75, 210, 110), outline=0, fill="ORANGE") - #draw.text((15, 85), "Input / Output Tests", fill="ORANGE", font=impact20) - # draw.rectangle((5, 135, 210, 170), outline=0, fill="ORANGE") - #draw.text((15, 120), "Current Network: " + currentnetwork, fill="ORANGE", font=impact20) - # draw.rectangle((5, 170, 210, 205), outline=0, fill="ORANGE") - #draw.text((15, 155), "Version Info", fill="ORANGE", font=impact20) - draw.rectangle((5, 40, 210, 75), outline=0, fill="ORANGE") - draw.text((15, 45), "Donate to SeedSigner", fill="BLACK", font=impact20) - draw.text((18, 210), "Press Control Stick to Select", fill="ORANGE", font=impact18) - disp.ShowImage(image, 0, 0) - -def settings_menu(runstate): - localrunstate = runstate - running = True - optionselected = 1 - while running == True: - optionselected = menu_elevator(optionselected, 5) - if optionselected == 1: - settings_option1() - if optionselected == 2: - settings_option2() - if optionselected == 3: - settings_option3() - if optionselected == 4: - settings_option4() - if optionselected == 5: - settings_option5() - if GPIO.input(KEY_PRESS_PIN) == GPIO.LOW: - if optionselected == 1: - time.sleep(0.2) - running = False - localrunstate[0] = 0 - return localrunstate - if optionselected == 2: - time.sleep(0.2) - running = False - localrunstate[0] = 50 - return localrunstate - if optionselected == 3: - time.sleep(0.2) - running = False - localrunstate[0] = 61 - return localrunstate - if optionselected == 4: - time.sleep(0.2) - running = False - localrunstate[0] = 57 - return localrunstate - if optionselected == 5: - time.sleep(0.2) - running = False - localrunstate[0] = 56 - return localrunstate - -#SEED GENERATION TOOLS MENU -#SEED GENERATION TOOLS MENU -#SEED GENERATION TOOLS MENU - -def seedselect_menu_option1(): - global savedseed1status, savedseed2status, savedseed3status - draw.rectangle((0, 0, width, height), outline=0, fill=0) - textwidth, textheight = draw.textsize("Select a Seed Slot", font=impact20) - draw.text(((240 - textwidth) / 2, 2), "Select a Seed Slot", fill="ORANGE", font=impact20) - draw.rectangle((5, 40, 210, 75), outline=0, fill="ORANGE") - draw.text((15, 45), "... ( return to MAIN )", fill="BLACK", font=impact20) - # draw.rectangle((5, 75, 210, 110), outline=0, fill="ORANGE") - draw.text((15, 80), "Use Seed Slot #1 " + savedseed1status, fill="ORANGE", font=impact20) - # draw.rectangle((5, 110, 210, 145), outline=0, fill="ORANGE") - draw.text((15, 115), "Use Seed Slot #2 " + savedseed2status, fill="ORANGE", font=impact20) - # draw.rectangle((5, 145, 210, 180), outline=0, fill="ORANGE") - draw.text((15, 150), "Use Seed Slot #3 " + savedseed3status, fill="ORANGE", font=impact20) - draw.text((18, 210), "Press Control Stick to Select", fill="ORANGE", font=impact18) - disp.ShowImage(image, 0, 0) - -def seedselect_menu_option2(): - global savedseed1status, savedseed2status, savedseed3status - draw.rectangle((0, 0, width, height), outline=0, fill=0) - textwidth, textheight = draw.textsize("Select a Seed Slot", font=impact20) - draw.text(((240 - textwidth) / 2, 2), "Select a Seed Slot", fill="ORANGE", font=impact20) - #draw.rectangle((5, 40, 210, 75), outline=0, fill="ORANGE") - draw.text((15, 45), "... ( return to MAIN )", fill="ORANGE", font=impact20) - draw.rectangle((5, 75, 210, 110), outline=0, fill="ORANGE") - draw.text((15, 80), "Use Seed Slot #1 " + savedseed1status, fill="BLACK", font=impact20) - # draw.rectangle((5, 110, 210, 145), outline=0, fill="ORANGE") - draw.text((15, 115), "Use Seed Slot #2 " + savedseed2status, fill="ORANGE", font=impact20) - # draw.rectangle((5, 145, 210, 180), outline=0, fill="ORANGE") - draw.text((15, 150), "Use Seed Slot #3 " + savedseed3status, fill="ORANGE", font=impact20) - draw.text((18, 210), "Press Control Stick to Select", fill="ORANGE", font=impact18) - disp.ShowImage(image, 0, 0) - -def seedselect_menu_option3(): - global savedseed1status, savedseed2status, savedseed3status - draw.rectangle((0, 0, width, height), outline=0, fill=0) - textwidth, textheight = draw.textsize("Select a Seed Slot", font=impact20) - draw.text(((240 - textwidth) / 2, 2), "Select a Seed Slot", fill="ORANGE", font=impact20) - #draw.rectangle((5, 40, 210, 75), outline=0, fill="ORANGE") - draw.text((15, 45), "... ( return to MAIN )", fill="ORANGE", font=impact20) - # draw.rectangle((5, 75, 210, 110), outline=0, fill="ORANGE") - draw.text((15, 80), "Use Seed Slot #1 " + savedseed1status, fill="ORANGE", font=impact20) - draw.rectangle((5, 110, 210, 145), outline=0, fill="ORANGE") - draw.text((15, 115), "Use Seed Slot #2 " + savedseed2status, fill="BLACK", font=impact20) - # draw.rectangle((5, 145, 210, 180), outline=0, fill="ORANGE") - draw.text((15, 150), "Use Seed Slot #3 " + savedseed3status, fill="ORANGE", font=impact20) - draw.text((18, 210), "Press Control Stick to Select", fill="ORANGE", font=impact18) - disp.ShowImage(image, 0, 0) - -def seedselect_menu_option4(): - draw.rectangle((0, 0, width, height), outline=0, fill=0) - textwidth, textheight = draw.textsize("Select a Seed Slot", font=impact20) - draw.text(((240 - textwidth) / 2, 2), "Select a Seed Slot", fill="ORANGE", font=impact20) - #draw.rectangle((5, 40, 210, 75), outline=0, fill="ORANGE") - draw.text((15, 45), "... ( return to MAIN )", fill="ORANGE", font=impact20) - # draw.rectangle((5, 75, 210, 110), outline=0, fill="ORANGE") - draw.text((15, 80), "Use Seed Slot #1 " + savedseed1status, fill="ORANGE", font=impact20) - # draw.rectangle((5, 110, 210, 145), outline=0, fill="ORANGE") - draw.text((15, 115), "Use Seed Slot #2" + savedseed2status, fill="ORANGE", font=impact20) - draw.rectangle((5, 145, 210, 180), outline=0, fill="ORANGE") - draw.text((15, 150), "Use Seed Slot #3" + savedseed3status, fill="BLACK", font=impact20) - draw.text((18, 210), "Press Control Stick to Select", fill="ORANGE", font=impact18) - disp.ShowImage(image, 0, 0) - -def seedselect_menu(runstate): - global activeseedsaveslot - global savedseed1status - global savedseed2status - global savedseed3status - localrunstate = runstate - running = True - optionselected = 1 - if localrunstate[2][0] == "": - savedseed1status = "" - else: - savedseed1status = " +" - if localrunstate[2][1] == "": - savedseed2status = "" - else: - savedseed2status = " +" - if localrunstate[2][2] == "": - savedseed3status = "" - else: - savedseed3status = " +" - while running == True: - optionselected = menu_elevator(optionselected, 4) - if optionselected == 1: - seedselect_menu_option1() - if optionselected == 2: - seedselect_menu_option2() - if optionselected == 3: - seedselect_menu_option3() - if optionselected == 4: - seedselect_menu_option4() - if GPIO.input(KEY_PRESS_PIN) == GPIO.LOW: - if optionselected == 1: - time.sleep(0.2) - running = False - localrunstate[0] = 0 - return localrunstate - if optionselected == 2: - time.sleep(0.2) - running = False - activeseedsaveslot = 1 - localrunstate[0] = 63 - return localrunstate - if optionselected == 3: - time.sleep(0.2) - running = False - activeseedsaveslot = 2 - localrunstate[0] = 63 - return localrunstate - if optionselected == 4: - time.sleep(0.2) - running = False - activeseedsaveslot = 3 - localrunstate[0] = 63 - return localrunstate - -def seedgen_menu_option1(): - draw.rectangle((0, 0, width, height), outline=0, fill=0) - textwidth, textheight = draw.textsize("Seed Tools", font=impact20) - draw.text(((240 - textwidth) / 2, 2), "Seed Tools", fill="ORANGE", font=impact20) - draw.rectangle((5, 40, 210, 75), outline=0, fill="ORANGE") - draw.text((15, 45), "... ( return to MAIN )", fill="BLACK", font=impact20) - #draw.rectangle((5, 75, 210, 110), outline=0, fill="ORANGE") - draw.text((15, 80), "Generate Word 12 / 24", fill="ORANGE", font=impact20) - # draw.rectangle((5, 110, 210, 145), outline=0, fill="ORANGE") - draw.text((15, 115), "Create a Seed w/ Dice", fill="ORANGE", font=impact20) - # draw.rectangle((5, 145, 210, 180), outline=0, fill="ORANGE") - draw.text((15, 150), "Store a Seed (temp)", fill="ORANGE", font=impact20) - draw.text((18, 210), "Press Control Stick to Select", fill="ORANGE", font=impact18) - disp.ShowImage(image, 0, 0) - -def seedgen_menu_option2(): - draw.rectangle((0, 0, width, height), outline=0, fill=0) - textwidth, textheight = draw.textsize("Seed Tools", font=impact20) - draw.text(((240 - textwidth) / 2, 2), "Seed Tools", fill="ORANGE", font=impact20) - #draw.rectangle((5, 40, 210, 75), outline=0, fill="ORANGE") - draw.text((15, 45), "... ( return to MAIN )", fill="ORANGE", font=impact20) - draw.rectangle((5, 75, 210, 110), outline=0, fill="ORANGE") - draw.text((15, 80), "Generate Word 12 / 24", fill="BLACK", font=impact20) - # draw.rectangle((5, 110, 210, 145), outline=0, fill="ORANGE") - draw.text((15, 115), "Create a Seed w/ Dice", fill="ORANGE", font=impact20) - # draw.rectangle((5, 145, 210, 180), outline=0, fill="ORANGE") - draw.text((15, 150), "Store a Seed (temp)", fill="ORANGE", font=impact20) - draw.text((18, 210), "Press Control Stick to Select", fill="ORANGE", font=impact18) - disp.ShowImage(image, 0, 0) - -def seedgen_menu_option3(): - draw.rectangle((0, 0, width, height), outline=0, fill=0) - textwidth, textheight = draw.textsize("Seed Tools", font=impact20) - draw.text(((240 - textwidth) / 2, 2), "Seed Tools", fill="ORANGE", font=impact20) - #draw.rectangle((5, 40, 210, 75), outline=0, fill="ORANGE") - draw.text((15, 45), "... ( return to MAIN )", fill="ORANGE", font=impact20) - #draw.rectangle((5, 75, 210, 110), outline=0, fill="ORANGE") - draw.text((15, 80), "Generate Word 12 / 24", fill="ORANGE", font=impact20) - draw.rectangle((5, 110, 210, 145), outline=0, fill="ORANGE") - draw.text((15, 115), "Create a Seed w/ Dice", fill="BLACK", font=impact20) - # draw.rectangle((5, 145, 210, 180), outline=0, fill="ORANGE") - draw.text((15, 150), "Store a Seed (temp)", fill="ORANGE", font=impact20) - draw.text((18, 210), "Press Control Stick to Select", fill="ORANGE", font=impact18) - disp.ShowImage(image, 0, 0) - -def seedgen_menu_option4(): - draw.rectangle((0, 0, width, height), outline=0, fill=0) - textwidth, textheight = draw.textsize("Seed Tools", font=impact20) - draw.text(((240 - textwidth) / 2, 2), "Seed Tools", fill="ORANGE", font=impact20) - #draw.rectangle((5, 40, 210, 75), outline=0, fill="ORANGE") - draw.text((15, 45), "... ( return to MAIN )", fill="ORANGE", font=impact20) - #draw.rectangle((5, 75, 210, 110), outline=0, fill="ORANGE") - draw.text((15, 80), "Generate Word 12 / 24", fill="ORANGE", font=impact20) - #draw.rectangle((5, 110, 210, 145), outline=0, fill="ORANGE") - draw.text((15, 115), "Create a Seed w/ Dice", fill="ORANGE", font=impact20) - draw.rectangle((5, 145, 210, 180), outline=0, fill="ORANGE") - draw.text((15, 150), "Store a Seed (temp)", fill="BLACK", font=impact20) - draw.text((18, 210), "Press Control Stick to Select", fill="ORANGE", font=impact18) - disp.ShowImage(image, 0, 0) - -def seedgen_menu(runstate): - localrunstate = runstate - running = True - optionselected = 1 - while running == True: - optionselected = menu_elevator(optionselected, 4) - if optionselected == 1: - seedgen_menu_option1() - if optionselected == 2: - seedgen_menu_option2() - if optionselected == 3: - seedgen_menu_option3() - if optionselected == 4: - seedgen_menu_option4() - if GPIO.input(KEY_PRESS_PIN) == GPIO.LOW: - if optionselected == 1: - time.sleep(0.2) - running = False - localrunstate[0] = 0 - return localrunstate - if optionselected == 2: - time.sleep(0.2) - running = False - localrunstate[0] = 51 - return localrunstate - if optionselected == 3: - time.sleep(0.2) - running = False - localrunstate[0] = 53 - return localrunstate - if optionselected == 4: - time.sleep(0.2) - running = False - localrunstate[0] = 62 - return localrunstate - -def decideifusedsavedwords_menu_option1(): - draw.rectangle((0, 0, width, height), outline=0, fill=0) - textwidth, textheight = draw.textsize("Use a saved seed?", font=impact20) - draw.text(((240 - textwidth) / 2, 2), "Use a saved seed?", fill="ORANGE", font=impact20) - draw.rectangle((5, 40, 210, 75), outline=0, fill="ORANGE") - draw.text((15, 45), "Yes", fill="BLACK", font=impact20) - #draw.rectangle((5, 75, 210, 110), outline=0, fill="ORANGE") - draw.text((15, 80), "No", fill="ORANGE", font=impact20) - draw.text((18, 210), "Press Control Stick to Select", fill="ORANGE", font=impact18) - disp.ShowImage(image, 0, 0) - -def decideifusedsavedwords_menu_option2(): - draw.rectangle((0, 0, width, height), outline=0, fill=0) - textwidth, textheight = draw.textsize("Use a saved seed?", font=impact20) - draw.text(((240 - textwidth) / 2, 2), "Use a saved seed?", fill="ORANGE", font=impact20) - #draw.rectangle((5, 40, 210, 75), outline=0, fill="ORANGE") - draw.text((15, 45), "Yes", fill="ORANGE", font=impact20) - draw.rectangle((5, 75, 210, 110), outline=0, fill="ORANGE") - draw.text((15, 80), "No", fill="BLACK", font=impact20) - draw.text((18, 210), "Press Control Stick to Select", fill="ORANGE", font=impact18) - disp.ShowImage(image, 0, 0) - -def decideifusesavedwords(): - running = True - optionselected = 1 - while running == True: - optionselected = menu_elevator(optionselected, 2) - if optionselected == 1: - decideifusedsavedwords_menu_option1() - if optionselected == 2: - decideifusedsavedwords_menu_option2() - if GPIO.input(KEY_PRESS_PIN) == GPIO.LOW: - if optionselected == 1: - time.sleep(0.2) - running = False - return "yes" - if optionselected == 2: - time.sleep(0.2) - running = False - return "no" - -#SIGNING TOOLS MENU -#SIGNING TOOLS MENU -#SIGNING TOOLS MENU - -def signing_menu_option1(): - draw.rectangle((0, 0, width, height), outline=0, fill=0) - draw.text((60, 2), "Signing Tools", fill="ORANGE", font=impact20) - draw.rectangle((5, 40, 210, 75), outline=0, fill="ORANGE") - draw.text((15, 45), "... ( return to MAIN )", fill="BLACK", font=impact20) - #draw.rectangle((5, 75, 210, 110), outline=0, fill="ORANGE") - draw.text((15, 80), "Generate XPUB", fill="ORANGE", font=impact20) - # draw.rectangle((5, 110, 210, 145), outline=0, fill="ORANGE") - draw.text((15, 115), "Sign a Transaction", fill="ORANGE", font=impact20) - draw.text((18, 210), "Press Control Stick to Select", fill="ORANGE", font=impact18) - disp.ShowImage(image, 0, 0) - -def signing_menu_option2(): - draw.rectangle((0, 0, width, height), outline=0, fill=0) - draw.text((60, 2), "Signing Tools", fill="ORANGE", font=impact20) - #draw.rectangle((5, 40, 210, 75), outline=0, fill="ORANGE") - draw.text((15, 45), "... ( return to MAIN )", fill="ORANGE", font=impact20) - draw.rectangle((5, 75, 210, 110), outline=0, fill="ORANGE") - draw.text((15, 80), "Generate XPUB", fill="BLACK", font=impact20) - # draw.rectangle((5, 110, 210, 145), outline=0, fill="ORANGE") - draw.text((15, 115), "Sign a Transaction", fill="ORANGE", font=impact20) - draw.text((18, 210), "Press Control Stick to Select", fill="ORANGE", font=impact18) - disp.ShowImage(image, 0, 0) - -def signing_menu_option3(): - draw.rectangle((0, 0, width, height), outline=0, fill=0) - draw.text((60, 2), "Signing Tools", fill="ORANGE", font=impact20) - #draw.rectangle((5, 40, 210, 75), outline=0, fill="ORANGE") - draw.text((15, 45), "... ( return to MAIN )", fill="ORANGE", font=impact20) - #draw.rectangle((5, 75, 210, 110), outline=0, fill="ORANGE") - draw.text((15, 80), "Generate XPUB", fill="ORANGE", font=impact20) - draw.rectangle((5, 110, 210, 145), outline=0, fill="ORANGE") - draw.text((15, 115), "Sign a Transaction", fill="BLACK", font=impact20) - draw.text((18, 210), "Press Control Stick to Select", fill="ORANGE", font=impact18) - disp.ShowImage(image, 0, 0) - -def signing_menu(runstate): - localrunstate = runstate - running = True - optionselected = 1 - while running == True: - optionselected = menu_elevator(optionselected, 3) - if optionselected == 1: - signing_menu_option1() - if optionselected == 2: - signing_menu_option2() - if optionselected == 3: - signing_menu_option3() - if GPIO.input(KEY_PRESS_PIN) == GPIO.LOW: - if optionselected == 1: - time.sleep(0.2) - running = False - localrunstate[0] = 0 - return localrunstate - if optionselected == 2: - time.sleep(0.2) - running = False - localrunstate[0] = 54 - return localrunstate - if optionselected == 3: - time.sleep(0.2) - running = False - localrunstate[0] = 55 - return localrunstate - -#DONATE MENU -#DONATE MENU -#DONATE MENU - -def donate(runstate): - localrunstate = runstate - - running1 = True - running2 = True - while running1 == True: - line1 = "You can support" - line2 = "SeedSigner by donating" - line3 = "any amount of BTC." - line4 = "Thank You!!!" - line5 = "(Press right for a QR code)" - - draw.rectangle((0, 0, width, height), outline=0, fill=0) - textwidth, textheight = draw.textsize(line1, font=impact22) - draw.text(((240 - textwidth) / 2, 20), line1, fill="ORANGE", font=impact22) - textwidth, textheight = draw.textsize(line2, font=impact22) - draw.text(((240 - textwidth) / 2, 55), line2, fill="ORANGE", font=impact22) - textwidth, textheight = draw.textsize(line3, font=impact22) - draw.text(((240 - textwidth) / 2, 90), line3, fill="ORANGE", font=impact22) - textwidth, textheight = draw.textsize(line4, font=impact22) - draw.text(((240 - textwidth) / 2, 125), line4, fill="ORANGE", font=impact22) - textwidth, textheight = draw.textsize(line5, font=impact22) - draw.text(((240 - textwidth) / 2, 190), line5, fill="ORANGE", font=impact22) - disp.ShowImage(image, 0, 0) - - if GPIO.input(KEY_RIGHT_PIN) == GPIO.LOW: - time.sleep(0.4) - running1 = False - - donationqr = qrcode.make("bc1q8u3dyltlg6pu56fe7m58aqz9cwrfld0s03zlrjl0wvm9x4nfa60q2l0g97").resize( - (240, 240)).convert('RGB') - - while running2 == True: - disp.ShowImage(donationqr, 0, 0) - - if GPIO.input(KEY_RIGHT_PIN) == GPIO.LOW: - time.sleep(0.4) - running2 = False - - localrunstate[0] = 3 - - return localrunstate - -#VERSTION MENU -#VERSTION MENU -#VERSTION MENU - -def version_info(runstate): - localrunstate = runstate - - running = True - while running == True: - line1 = "SeedSigner" - line2 = "Version " + version - line3 = "built for use with" - line4 = "Specter-desktop" - line5 = "v1.1.0 or higher" - line6 = "(Joystick RIGHT to EXIT)" - - draw.rectangle((0, 0, width, height), outline=0, fill=0) - textwidth, textheight = draw.textsize(line1, font=impact22) - draw.text(((240 - textwidth) / 2, 20), line1, fill="ORANGE", font=impact22) - textwidth, textheight = draw.textsize(line2, font=impact22) - draw.text(((240 - textwidth) / 2, 55), line2, fill="ORANGE", font=impact22) - textwidth, textheight = draw.textsize(line3, font=impact22) - draw.text(((240 - textwidth) / 2, 90), line3, fill="ORANGE", font=impact22) - textwidth, textheight = draw.textsize(line4, font=impact22) - draw.text(((240 - textwidth) / 2, 125), line4, fill="ORANGE", font=impact22) - textwidth, textheight = draw.textsize(line5, font=impact22) - draw.text(((240 - textwidth) / 2, 160), line5, fill="ORANGE", font=impact22) - textwidth, textheight = draw.textsize(line6, font=impact18) - draw.text(((240 - textwidth) / 2, 210), line6, fill="ORANGE", font=impact18) - disp.ShowImage(image, 0, 0) - - if GPIO.input(KEY_RIGHT_PIN) == GPIO.LOW: - time.sleep(0.4) - running = False - - localrunstate[0] = 3 - - return localrunstate - -#SELECT NUMBER OF WORDS MENU -#SELECT NUMBER OF WORDS MENU -#SELECT NUMBER OF WORDS MENU - -def numofwords_menu_option1(): - draw.rectangle((0, 0, width, height), outline=0, fill=0) - textwidth, textheight = draw.textsize("12 or 24 Word Seed?", font=impact20) - draw.text(((240 - textwidth) / 2, 2), "12 or 24 Word Seed?", fill="ORANGE", font=impact20) - draw.rectangle((5, 40, 210, 75), outline=0, fill="ORANGE") - draw.text((15, 45), "... ( return to MAIN )", fill="BLACK", font=impact20) - #draw.rectangle((5, 75, 210, 110), outline=0, fill="ORANGE") - draw.text((15, 80), "Use a 12 word seed", fill="ORANGE", font=impact20) - # draw.rectangle((5, 110, 210, 145), outline=0, fill="ORANGE") - draw.text((15, 115), "Use a 24 word seed", fill="ORANGE", font=impact20) - draw.text((18, 210), "Press Control Stick to Select", fill="ORANGE", font=impact18) - disp.ShowImage(image, 0, 0) - -def numofwords_menu_option2(): - draw.rectangle((0, 0, width, height), outline=0, fill=0) - textwidth, textheight = draw.textsize("12 or 24 Word Seed?", font=impact20) - draw.text(((240 - textwidth) / 2, 2), "12 or 24 Word Seed?", fill="ORANGE", font=impact20) - #draw.rectangle((5, 40, 210, 75), outline=0, fill="ORANGE") - draw.text((15, 45), "... ( return to MAIN )", fill="ORANGE", font=impact20) - draw.rectangle((5, 75, 210, 110), outline=0, fill="ORANGE") - draw.text((15, 80), "Use a 12 word seed", fill="BLACK", font=impact20) - # draw.rectangle((5, 110, 210, 145), outline=0, fill="ORANGE") - draw.text((15, 115), "Use a 24 word seed", fill="ORANGE", font=impact20) - draw.text((18, 210), "Press Control Stick to Select", fill="ORANGE", font=impact18) - disp.ShowImage(image, 0, 0) - -def numofwords_menu_option3(): - draw.rectangle((0, 0, width, height), outline=0, fill=0) - textwidth, textheight = draw.textsize("12 or 24 Word Seed?", font=impact20) - draw.text(((240 - textwidth) / 2, 2), "12 or 24 Word Seed?", fill="ORANGE", font=impact20) - #draw.rectangle((5, 40, 210, 75), outline=0, fill="ORANGE") - draw.text((15, 45), "... ( return to MAIN )", fill="ORANGE", font=impact20) - #draw.rectangle((5, 75, 210, 110), outline=0, fill="ORANGE") - draw.text((15, 80), "Use a 12 word seed", fill="ORANGE", font=impact20) - draw.rectangle((5, 110, 210, 145), outline=0, fill="ORANGE") - draw.text((15, 115), "Use a 24 word seed", fill="BLACK", font=impact20) - draw.text((18, 210), "Press Control Stick to Select", fill="ORANGE", font=impact18) - disp.ShowImage(image, 0, 0) - -def numofwords_menu(): - running = True - optionselected = 1 - while running == True: - optionselected = menu_elevator(optionselected, 3) - if optionselected == 1: - numofwords_menu_option1() - if optionselected == 2: - numofwords_menu_option2() - if optionselected == 3: - numofwords_menu_option3() - if GPIO.input(KEY_PRESS_PIN) == GPIO.LOW: - if optionselected == 1: - time.sleep(0.2) - running = False - return "abort" - if optionselected == 2: - time.sleep(0.2) - running = False - return 12 - if optionselected == 3: - time.sleep(0.2) - running = False - return 24 - -# SELECT NETWORK MENU -# SELECT NETWORK MENU -# SELECT NETWORK MENU - -def network_menu_option1(): - draw.rectangle((0, 0, width, height), outline=0, fill=0) - textwidth, textheight = draw.textsize("Which Network?", font=impact20) - draw.text(((240 - textwidth) / 2, 2), "Which Network?", fill="ORANGE", font=impact20) - draw.rectangle((5, 40, 210, 75), outline=0, fill="ORANGE") - draw.text((15, 45), "... ( return to SETTINGS )", fill="BLACK", font=impact20) - #draw.rectangle((5, 75, 210, 110), outline=0, fill="ORANGE") - draw.text((15, 80), "Use Mainnet", fill="ORANGE", font=impact20) - # draw.rectangle((5, 110, 210, 145), outline=0, fill="ORANGE") - draw.text((15, 115), "Use Testnet", fill="ORANGE", font=impact20) - draw.text((18, 210), "Press Control Stick to Select", fill="ORANGE", font=impact18) - disp.ShowImage(image, 0, 0) - -def network_menu_option2(): - draw.rectangle((0, 0, width, height), outline=0, fill=0) - textwidth, textheight = draw.textsize("Which Network?", font=impact20) - draw.text(((240 - textwidth) / 2, 2), "Which Network?", fill="ORANGE", font=impact20) - #draw.rectangle((5, 40, 210, 75), outline=0, fill="ORANGE") - draw.text((15, 45), "... ( return to SETTINGS )", fill="ORANGE", font=impact20) - draw.rectangle((5, 75, 210, 110), outline=0, fill="ORANGE") - draw.text((15, 80), "Use Mainnet", fill="BLACK", font=impact20) - # draw.rectangle((5, 110, 210, 145), outline=0, fill="ORANGE") - draw.text((15, 115), "Use Testnet", fill="ORANGE", font=impact20) - draw.text((18, 210), "Press Control Stick to Select", fill="ORANGE", font=impact18) - disp.ShowImage(image, 0, 0) - -def network_menu_option3(): - draw.rectangle((0, 0, width, height), outline=0, fill=0) - textwidth, textheight = draw.textsize("Which Network?", font=impact20) - draw.text(((240 - textwidth) / 2, 2), "Which Network?", fill="ORANGE", font=impact20) - #draw.rectangle((5, 40, 210, 75), outline=0, fill="ORANGE") - draw.text((15, 45), "... ( return to SETTINGS )", fill="ORANGE", font=impact20) - # draw.rectangle((5, 75, 210, 110), outline=0, fill="ORANGE") - draw.text((15, 80), "Use Mainnet", fill="ORANGE", font=impact20) - draw.rectangle((5, 110, 210, 145), outline=0, fill="ORANGE") - draw.text((15, 115), "Use Testnet", fill="BLACK", font=impact20) - draw.text((18, 210), "Press Control Stick to Select", fill="ORANGE", font=impact18) - disp.ShowImage(image, 0, 0) - -def network_menu(runstate): - localrunstate = runstate - - global currentnetwork - global hardened_derivation - - running = True - optionselected = 1 - while running == True: - optionselected = menu_elevator(optionselected, 3) - if optionselected == 1: - network_menu_option1() - if optionselected == 2: - network_menu_option2() - if optionselected == 3: - network_menu_option3() - if GPIO.input(KEY_PRESS_PIN) == GPIO.LOW: - if optionselected == 1: - time.sleep(0.2) - localrunstate[0] = 3 - running = False - return localrunstate - if optionselected == 2: - time.sleep(0.2) - currentnetwork = "main" - hardened_derivation = "m/48h/0h/0h/2h" - localrunstate[0] = 3 - running = False - return localrunstate - if optionselected == 3: - time.sleep(0.2) - currentnetwork = "test" - hardened_derivation = "m/48h/1h/0h/2h" - localrunstate[0] = 3 - running = False - return localrunstate - -# BEGIN IO TEST MODULE -# BEGIN IO TEST MODULE -# BEGIN IO TEST MODULE - -def iotestscreen(runstate): - localrunstate = runstate - - draw.rectangle((0, 0, width, height), outline=0, fill=0) - textwidth, textheight = draw.textsize("Initializing I/O Test", font=impact22) - draw.text(((240 - textwidth) / 2, 100), "Initializing I/O Test", fill="ORANGE", font=impact22) - disp.ShowImage(image, 0, 0) - - scannedqrs = 0 - vs = VideoStream(usePiCamera=True).start() # For Pi Camera - time.sleep(2.0) - - draw.rectangle((0,0,width,height), outline=0, fill=0) - draw.text((45, 5), "Input/Output Check:", fill="ORANGE", font=impact18) - draw.polygon([(61, 89), (80, 46), (99, 89)], outline="ORANGE", fill=0) - draw.polygon([(51, 100), (8, 119), (51, 138)], outline="ORANGE", fill=0) - draw.polygon([(109, 100), (152, 119), (109, 138)], outline="ORANGE", fill=0) - draw.polygon([(61, 151), (80, 193), (99, 151)], outline="ORANGE", fill=0) - draw.ellipse([(61, 99), (99, 141)], outline="ORANGE", fill=0) - draw.ellipse([(198, 40), (238, 80)], outline="ORANGE", fill=0) - draw.ellipse([(198, 95), (238, 135)], outline="ORANGE", fill=0) - draw.text((200, 160), "EXIT", fill="ORANGE", font=impact18) - prescantext = "Scan ANY QR Code" - textwidth, textheight = draw.textsize(prescantext, font=impact22) - draw.text(((240 - textwidth) / 2, 205), prescantext, fill="ORANGE", font=impact22) - disp.ShowImage(image, 0, 0) - - running = True - - - while running == True: - frame = vs.read() - frame = imutils.resize(frame, width=400) - barcodes = pyzbar.decode(frame) - for barcode in barcodes: - scannedqrs += 1 - #time.sleep(0.1) - #time.sleep(0.05) - - draw.rectangle((0, 0, width, height), outline=0, fill=0) - draw.text((45, 5), "Input/Output Check:", fill="ORANGE", font=impact18) - - if GPIO.input(KEY_UP_PIN) == GPIO.LOW: # button is released - #time.sleep(0.1) - draw.polygon([(61, 89), (80, 46), (99, 89)], outline="ORANGE", fill="ORANGE") - else: # button is pressed: - draw.polygon([(61, 89), (80, 46), (99, 89)], outline="ORANGE", fill=0) - - if GPIO.input(KEY_LEFT_PIN) == GPIO.LOW: # button is released - #time.sleep(0.1) - draw.polygon([(51, 100), (8, 119), (51, 138)], outline="ORANGE", fill="ORANGE") - else: # button is pressed: - draw.polygon([(51, 100), (8, 119), (51, 138)], outline="ORANGE", fill=0) - - if GPIO.input(KEY_RIGHT_PIN) == GPIO.LOW: # button is released - #time.sleep(0.1) - draw.polygon([(109, 100), (152, 119), (109, 138)], outline="ORANGE", fill="ORANGE") - else: # button is pressed: - draw.polygon([(109, 100), (152, 119), (109, 138)], outline="ORANGE", fill=0) - - if GPIO.input(KEY_DOWN_PIN) == GPIO.LOW: # button is released - #time.sleep(0.1) - draw.polygon([(61, 151), (80, 193), (99, 151)], outline="ORANGE", fill="ORANGE") - else: # button is pressed: - draw.polygon([(61, 151), (80, 193), (99, 151)], outline="ORANGE", fill=0) - - if GPIO.input(KEY_PRESS_PIN) == GPIO.LOW: # button is released - #time.sleep(0.1) - draw.ellipse([(61, 99), (99, 141)], outline="ORANGE", fill="ORANGE") - else: # button is pressed: - draw.ellipse([(61, 99), (99, 141)], outline="ORANGE", fill=0) - - if GPIO.input(KEY1_PIN) == GPIO.LOW: # button is released - #time.sleep(0.1) - draw.ellipse([(198, 40), (238, 80)], outline="ORANGE", fill="ORANGE") - else: # button is pressed: - draw.ellipse([(198, 40), (238, 80)], outline="ORANGE", fill=0) - - if GPIO.input(KEY2_PIN) == GPIO.LOW: # button is released - #time.sleep(0.1) - draw.ellipse([(198, 95), (238, 135)], outline="ORANGE", fill="ORANGE") - else: # button is pressed: - draw.ellipse([(198, 95), (238, 135)], outline="ORANGE", fill=0) - - draw.text((200, 160), "EXIT", fill="ORANGE", font=impact18) - - scansuccesstext = "QR code scanned!" - if scannedqrs == 0: - textwidth, textheight = draw.textsize(prescantext, font=impact22) - draw.text(((240-textwidth)/2, 205), prescantext, fill="ORANGE", font=impact22) - elif scannedqrs % 2 == 1: - textwidth, textheight = draw.textsize(scansuccesstext, font=impact22) - draw.rectangle((30, 205, 210, 235), outline="ORANGE", fill="ORANGE") - draw.text(((240 - textwidth) / 2, 205), scansuccesstext, fill="BLACK", font=impact22) - elif scannedqrs % 2 == 0: - textwidth, textheight = draw.textsize(scansuccesstext, font=impact22) - draw.rectangle((30, 205, 210, 235), outline="ORANGE", fill="BLACK") - draw.text(((240 - textwidth) / 2, 205), scansuccesstext, fill="ORANGE", font=impact22) - - if GPIO.input(KEY3_PIN) == GPIO.LOW: # button is released - time.sleep(0.4) - vs.stop() - running = False - localrunstate[0] = 3 - return localrunstate - - disp.ShowImage(image,0,0) - - print("You exited the i o test module") - -# GETWORDS MODULE -# GETWORDS MODULE -# GETWORDS MODULE - -#alphabet reference -alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"] - -#seed reference -seedwords = ["abandon", "ability", "able", "about", "above", "absent", "absorb", "abstract", "absurd", "abuse", "access", "accident", "account", "accuse", "achieve", "acid", "acoustic", "acquire", "across", "act", "action", "actor", "actress", "actual", "adapt", "add", "addict", "address", "adjust", "admit", "adult", "advance", "advice", "aerobic", "affair", "afford", "afraid", "again", "age", "agent", "agree", "ahead", "aim", "air", "airport", "aisle", "alarm", "album", "alcohol", "alert", "alien", "all", "alley", "allow", "almost", "alone", "alpha", "already", "also", "alter", "always", "amateur", "amazing", "among", "amount", "amused", "analyst", "anchor", "ancient", "anger", "angle", "angry", "animal", "ankle", "announce", "annual", "another", "answer", "antenna", "antique", "anxiety", "any", "apart", "apology", "appear", "apple", "approve", "april", "arch", "arctic", "area", "arena", "argue", "arm", "armed", "armor", "army", "around", "arrange", "arrest", "arrive", "arrow", "art", "artefact", "artist", "artwork", "ask", "aspect", "assault", "asset", "assist", "assume", "asthma", "athlete", "atom", "attack", "attend", "attitude", "attract", "auction", "audit", "august", "aunt", "author", "auto", "autumn", "average", "avocado", "avoid", "awake", "aware", "away", "awesome", "awful", "awkward", "axis", "baby", "bachelor", "bacon", "badge", "bag", "balance", "balcony", "ball", "bamboo", "banana", "banner", "bar", "barely", "bargain", "barrel", "base", "basic", "basket", "battle", "beach", "bean", "beauty", "because", "become", "beef", "before", "begin", "behave", "behind", "believe", "below", "belt", "bench", "benefit", "best", "betray", "better", "between", "beyond", "bicycle", "bid", "bike", "bind", "biology", "bird", "birth", "bitter", "black", "blade", "blame", "blanket", "blast", "bleak", "bless", "blind", "blood", "blossom", "blouse", "blue", "blur", "blush", "board", "boat", "body", "boil", "bomb", "bone", "bonus", "book", "boost", "border", "boring", "borrow", "boss", "bottom", "bounce", "box", "boy", "bracket", "brain", "brand", "brass", "brave", "bread", "breeze", "brick", "bridge", "brief", "bright", "bring", "brisk", "broccoli", "broken", "bronze", "broom", "brother", "brown", "brush", "bubble", "buddy", "budget", "buffalo", "build", "bulb", "bulk", "bullet", "bundle", "bunker", "burden", "burger", "burst", "bus", "business", "busy", "butter", "buyer", "buzz", "cabbage", "cabin", "cable", "cactus", "cage", "cake", "call", "calm", "camera", "camp", "can", "canal", "cancel", "candy", "cannon", "canoe", "canvas", "canyon", "capable", "capital", "captain", "car", "carbon", "card", "cargo", "carpet", "carry", "cart", "case", "cash", "casino", "castle", "casual", "cat", "catalog", "catch", "category", "cattle", "caught", "cause", "caution", "cave", "ceiling", "celery", "cement", "census", "century", "cereal", "certain", "chair", "chalk", "champion", "change", "chaos", "chapter", "charge", "chase", "chat", "cheap", "check", "cheese", "chef", "cherry", "chest", "chicken", "chief", "child", "chimney", "choice", "choose", "chronic", "chuckle", "chunk", "churn", "cigar", "cinnamon", "circle", "citizen", "city", "civil", "claim", "clap", "clarify", "claw", "clay", "clean", "clerk", "clever", "click", "client", "cliff", "climb", "clinic", "clip", "clock", "clog", "close", "cloth", "cloud", "clown", "club", "clump", "cluster", "clutch", "coach", "coast", "coconut", "code", "coffee", "coil", "coin", "collect", "color", "column", "combine", "come", "comfort", "comic", "common", "company", "concert", "conduct", "confirm", "congress", "connect", "consider", "control", "convince", "cook", "cool", "copper", "copy", "coral", "core", "corn", "correct", "cost", "cotton", "couch", "country", "couple", "course", "cousin", "cover", "coyote", "crack", "cradle", "craft", "cram", "crane", "crash", "crater", "crawl", "crazy", "cream", "credit", "creek", "crew", "cricket", "crime", "crisp", "critic", "crop", "cross", "crouch", "crowd", "crucial", "cruel", "cruise", "crumble", "crunch", "crush", "cry", "crystal", "cube", "culture", "cup", "cupboard", "curious", "current", "curtain", "curve", "cushion", "custom", "cute", "cycle", "dad", "damage", "damp", "dance", "danger", "daring", "dash", "daughter", "dawn", "day", "deal", "debate", "debris", "decade", "december", "decide", "decline", "decorate", "decrease", "deer", "defense", "define", "defy", "degree", "delay", "deliver", "demand", "demise", "denial", "dentist", "deny", "depart", "depend", "deposit", "depth", "deputy", "derive", "describe", "desert", "design", "desk", "despair", "destroy", "detail", "detect", "develop", "device", "devote", "diagram", "dial", "diamond", "diary", "dice", "diesel", "diet", "differ", "digital", "dignity", "dilemma", "dinner", "dinosaur", "direct", "dirt", "disagree", "discover", "disease", "dish", "dismiss", "disorder", "display", "distance", "divert", "divide", "divorce", "dizzy", "doctor", "document", "dog", "doll", "dolphin", "domain", "donate", "donkey", "donor", "door", "dose", "double", "dove", "draft", "dragon", "drama", "drastic", "draw", "dream", "dress", "drift", "drill", "drink", "drip", "drive", "drop", "drum", "dry", "duck", "dumb", "dune", "during", "dust", "dutch", "duty", "dwarf", "dynamic", "eager", "eagle", "early", "earn", "earth", "easily", "east", "easy", "echo", "ecology", "economy", "edge", "edit", "educate", "effort", "egg", "eight", "either", "elbow", "elder", "electric", "elegant", "element", "elephant", "elevator", "elite", "else", "embark", "embody", "embrace", "emerge", "emotion", "employ", "empower", "empty", "enable", "enact", "end", "endless", "endorse", "enemy", "energy", "enforce", "engage", "engine", "enhance", "enjoy", "enlist", "enough", "enrich", "enroll", "ensure", "enter", "entire", "entry", "envelope", "episode", "equal", "equip", "era", "erase", "erode", "erosion", "error", "erupt", "escape", "essay", "essence", "estate", "eternal", "ethics", "evidence", "evil", "evoke", "evolve", "exact", "example", "excess", "exchange", "excite", "exclude", "excuse", "execute", "exercise", "exhaust", "exhibit", "exile", "exist", "exit", "exotic", "expand", "expect", "expire", "explain", "expose", "express", "extend", "extra", "eye", "eyebrow", "fabric", "face", "faculty", "fade", "faint", "faith", "fall", "false", "fame", "family", "famous", "fan", "fancy", "fantasy", "farm", "fashion", "fat", "fatal", "father", "fatigue", "fault", "favorite", "feature", "february", "federal", "fee", "feed", "feel", "female", "fence", "festival", "fetch", "fever", "few", "fiber", "fiction", "field", "figure", "file", "film", "filter", "final", "find", "fine", "finger", "finish", "fire", "firm", "first", "fiscal", "fish", "fit", "fitness", "fix", "flag", "flame", "flash", "flat", "flavor", "flee", "flight", "flip", "float", "flock", "floor", "flower", "fluid", "flush", "fly", "foam", "focus", "fog", "foil", "fold", "follow", "food", "foot", "force", "forest", "forget", "fork", "fortune", "forum", "forward", "fossil", "foster", "found", "fox", "fragile", "frame", "frequent", "fresh", "friend", "fringe", "frog", "front", "frost", "frown", "frozen", "fruit", "fuel", "fun", "funny", "furnace", "fury", "future", "gadget", "gain", "galaxy", "gallery", "game", "gap", "garage", "garbage", "garden", "garlic", "garment", "gas", "gasp", "gate", "gather", "gauge", "gaze", "general", "genius", "genre", "gentle", "genuine", "gesture", "ghost", "giant", "gift", "giggle", "ginger", "giraffe", "girl", "give", "glad", "glance", "glare", "glass", "glide", "glimpse", "globe", "gloom", "glory", "glove", "glow", "glue", "goat", "goddess", "gold", "good", "goose", "gorilla", "gospel", "gossip", "govern", "gown", "grab", "grace", "grain", "grant", "grape", "grass", "gravity", "great", "green", "grid", "grief", "grit", "grocery", "group", "grow", "grunt", "guard", "guess", "guide", "guilt", "guitar", "gun", "gym", "habit", "hair", "half", "hammer", "hamster", "hand", "happy", "harbor", "hard", "harsh", "harvest", "hat", "have", "hawk", "hazard", "head", "health", "heart", "heavy", "hedgehog", "height", "hello", "helmet", "help", "hen", "hero", "hidden", "high", "hill", "hint", "hip", "hire", "history", "hobby", "hockey", "hold", "hole", "holiday", "hollow", "home", "honey", "hood", "hope", "horn", "horror", "horse", "hospital", "host", "hotel", "hour", "hover", "hub", "huge", "human", "humble", "humor", "hundred", "hungry", "hunt", "hurdle", "hurry", "hurt", "husband", "hybrid", "ice", "icon", "idea", "identify", "idle", "ignore", "ill", "illegal", "illness", "image", "imitate", "immense", "immune", "impact", "impose", "improve", "impulse", "inch", "include", "income", "increase", "index", "indicate", "indoor", "industry", "infant", "inflict", "inform", "inhale", "inherit", "initial", "inject", "injury", "inmate", "inner", "innocent", "input", "inquiry", "insane", "insect", "inside", "inspire", "install", "intact", "interest", "into", "invest", "invite", "involve", "iron", "island", "isolate", "issue", "item", "ivory", "jacket", "jaguar", "jar", "jazz", "jealous", "jeans", "jelly", "jewel", "job", "join", "joke", "journey", "joy", "judge", "juice", "jump", "jungle", "junior", "junk", "just", "kangaroo", "keen", "keep", "ketchup", "key", "kick", "kid", "kidney", "kind", "kingdom", "kiss", "kit", "kitchen", "kite", "kitten", "kiwi", "knee", "knife", "knock", "know", "lab", "label", "labor", "ladder", "lady", "lake", "lamp", "language", "laptop", "large", "later", "latin", "laugh", "laundry", "lava", "law", "lawn", "lawsuit", "layer", "lazy", "leader", "leaf", "learn", "leave", "lecture", "left", "leg", "legal", "legend", "leisure", "lemon", "lend", "length", "lens", "leopard", "lesson", "letter", "level", "liar", "liberty", "library", "license", "life", "lift", "light", "like", "limb", "limit", "link", "lion", "liquid", "list", "little", "live", "lizard", "load", "loan", "lobster", "local", "lock", "logic", "lonely", "long", "loop", "lottery", "loud", "lounge", "love", "loyal", "lucky", "luggage", "lumber", "lunar", "lunch", "luxury", "lyrics", "machine", "mad", "magic", "magnet", "maid", "mail", "main", "major", "make", "mammal", "man", "manage", "mandate", "mango", "mansion", "manual", "maple", "marble", "march", "margin", "marine", "market", "marriage", "mask", "mass", "master", "match", "material", "math", "matrix", "matter", "maximum", "maze", "meadow", "mean", "measure", "meat", "mechanic", "medal", "media", "melody", "melt", "member", "memory", "mention", "menu", "mercy", "merge", "merit", "merry", "mesh", "message", "metal", "method", "middle", "midnight", "milk", "million", "mimic", "mind", "minimum", "minor", "minute", "miracle", "mirror", "misery", "miss", "mistake", "mix", "mixed", "mixture", "mobile", "model", "modify", "mom", "moment", "monitor", "monkey", "monster", "month", "moon", "moral", "more", "morning", "mosquito", "mother", "motion", "motor", "mountain", "mouse", "move", "movie", "much", "muffin", "mule", "multiply", "muscle", "museum", "mushroom", "music", "must", "mutual", "myself", "mystery", "myth", "naive", "name", "napkin", "narrow", "nasty", "nation", "nature", "near", "neck", "need", "negative", "neglect", "neither", "nephew", "nerve", "nest", "net", "network", "neutral", "never", "news", "next", "nice", "night", "noble", "noise", "nominee", "noodle", "normal", "north", "nose", "notable", "note", "nothing", "notice", "novel", "now", "nuclear", "number", "nurse", "nut", "oak", "obey", "object", "oblige", "obscure", "observe", "obtain", "obvious", "occur", "ocean", "october", "odor", "off", "offer", "office", "often", "oil", "okay", "old", "olive", "olympic", "omit", "once", "one", "onion", "online", "only", "open", "opera", "opinion", "oppose", "option", "orange", "orbit", "orchard", "order", "ordinary", "organ", "orient", "original", "orphan", "ostrich", "other", "outdoor", "outer", "output", "outside", "oval", "oven", "over", "own", "owner", "oxygen", "oyster", "ozone", "pact", "paddle", "page", "pair", "palace", "palm", "panda", "panel", "panic", "panther", "paper", "parade", "parent", "park", "parrot", "party", "pass", "patch", "path", "patient", "patrol", "pattern", "pause", "pave", "payment", "peace", "peanut", "pear", "peasant", "pelican", "pen", "penalty", "pencil", "people", "pepper", "perfect", "permit", "person", "pet", "phone", "photo", "phrase", "physical", "piano", "picnic", "picture", "piece", "pig", "pigeon", "pill", "pilot", "pink", "pioneer", "pipe", "pistol", "pitch", "pizza", "place", "planet", "plastic", "plate", "play", "please", "pledge", "pluck", "plug", "plunge", "poem", "poet", "point", "polar", "pole", "police", "pond", "pony", "pool", "popular", "portion", "position", "possible", "post", "potato", "pottery", "poverty", "powder", "power", "practice", "praise", "predict", "prefer", "prepare", "present", "pretty", "prevent", "price", "pride", "primary", "print", "priority", "prison", "private", "prize", "problem", "process", "produce", "profit", "program", "project", "promote", "proof", "property", "prosper", "protect", "proud", "provide", "public", "pudding", "pull", "pulp", "pulse", "pumpkin", "punch", "pupil", "puppy", "purchase", "purity", "purpose", "purse", "push", "put", "puzzle", "pyramid", "quality", "quantum", "quarter", "question", "quick", "quit", "quiz", "quote", "rabbit", "raccoon", "race", "rack", "radar", "radio", "rail", "rain", "raise", "rally", "ramp", "ranch", "random", "range", "rapid", "rare", "rate", "rather", "raven", "raw", "razor", "ready", "real", "reason", "rebel", "rebuild", "recall", "receive", "recipe", "record", "recycle", "reduce", "reflect", "reform", "refuse", "region", "regret", "regular", "reject", "relax", "release", "relief", "rely", "remain", "remember", "remind", "remove", "render", "renew", "rent", "reopen", "repair", "repeat", "replace", "report", "require", "rescue", "resemble", "resist", "resource", "response", "result", "retire", "retreat", "return", "reunion", "reveal", "review", "reward", "rhythm", "rib", "ribbon", "rice", "rich", "ride", "ridge", "rifle", "right", "rigid", "ring", "riot", "ripple", "risk", "ritual", "rival", "river", "road", "roast", "robot", "robust", "rocket", "romance", "roof", "rookie", "room", "rose", "rotate", "rough", "round", "route", "royal", "rubber", "rude", "rug", "rule", "run", "runway", "rural", "sad", "saddle", "sadness", "safe", "sail", "salad", "salmon", "salon", "salt", "salute", "same", "sample", "sand", "satisfy", "satoshi", "sauce", "sausage", "save", "say", "scale", "scan", "scare", "scatter", "scene", "scheme", "school", "science", "scissors", "scorpion", "scout", "scrap", "screen", "script", "scrub", "sea", "search", "season", "seat", "second", "secret", "section", "security", "seed", "seek", "segment", "select", "sell", "seminar", "senior", "sense", "sentence", "series", "service", "session", "settle", "setup", "seven", "shadow", "shaft", "shallow", "share", "shed", "shell", "sheriff", "shield", "shift", "shine", "ship", "shiver", "shock", "shoe", "shoot", "shop", "short", "shoulder", "shove", "shrimp", "shrug", "shuffle", "shy", "sibling", "sick", "side", "siege", "sight", "sign", "silent", "silk", "silly", "silver", "similar", "simple", "since", "sing", "siren", "sister", "situate", "six", "size", "skate", "sketch", "ski", "skill", "skin", "skirt", "skull", "slab", "slam", "sleep", "slender", "slice", "slide", "slight", "slim", "slogan", "slot", "slow", "slush", "small", "smart", "smile", "smoke", "smooth", "snack", "snake", "snap", "sniff", "snow", "soap", "soccer", "social", "sock", "soda", "soft", "solar", "soldier", "solid", "solution", "solve", "someone", "song", "soon", "sorry", "sort", "soul", "sound", "soup", "source", "south", "space", "spare", "spatial", "spawn", "speak", "special", "speed", "spell", "spend", "sphere", "spice", "spider", "spike", "spin", "spirit", "split", "spoil", "sponsor", "spoon", "sport", "spot", "spray", "spread", "spring", "spy", "square", "squeeze", "squirrel", "stable", "stadium", "staff", "stage", "stairs", "stamp", "stand", "start", "state", "stay", "steak", "steel", "stem", "step", "stereo", "stick", "still", "sting", "stock", "stomach", "stone", "stool", "story", "stove", "strategy", "street", "strike", "strong", "struggle", "student", "stuff", "stumble", "style", "subject", "submit", "subway", "success", "such", "sudden", "suffer", "sugar", "suggest", "suit", "summer", "sun", "sunny", "sunset", "super", "supply", "supreme", "sure", "surface", "surge", "surprise", "surround", "survey", "suspect", "sustain", "swallow", "swamp", "swap", "swarm", "swear", "sweet", "swift", "swim", "swing", "switch", "sword", "symbol", "symptom", "syrup", "system", "table", "tackle", "tag", "tail", "talent", "talk", "tank", "tape", "target", "task", "taste", "tattoo", "taxi", "teach", "team", "tell", "ten", "tenant", "tennis", "tent", "term", "test", "text", "thank", "that", "theme", "then", "theory", "there", "they", "thing", "this", "thought", "three", "thrive", "throw", "thumb", "thunder", "ticket", "tide", "tiger", "tilt", "timber", "time", "tiny", "tip", "tired", "tissue", "title", "toast", "tobacco", "today", "toddler", "toe", "together", "toilet", "token", "tomato", "tomorrow", "tone", "tongue", "tonight", "tool", "tooth", "top", "topic", "topple", "torch", "tornado", "tortoise", "toss", "total", "tourist", "toward", "tower", "town", "toy", "track", "trade", "traffic", "tragic", "train", "transfer", "trap", "trash", "travel", "tray", "treat", "tree", "trend", "trial", "tribe", "trick", "trigger", "trim", "trip", "trophy", "trouble", "truck", "true", "truly", "trumpet", "trust", "truth", "try", "tube", "tuition", "tumble", "tuna", "tunnel", "turkey", "turn", "turtle", "twelve", "twenty", "twice", "twin", "twist", "two", "type", "typical", "ugly", "umbrella", "unable", "unaware", "uncle", "uncover", "under", "undo", "unfair", "unfold", "unhappy", "uniform", "unique", "unit", "universe", "unknown", "unlock", "until", "unusual", "unveil", "update", "upgrade", "uphold", "upon", "upper", "upset", "urban", "urge", "usage", "use", "used", "useful", "useless", "usual", "utility", "vacant", "vacuum", "vague", "valid", "valley", "valve", "van", "vanish", "vapor", "various", "vast", "vault", "vehicle", "velvet", "vendor", "venture", "venue", "verb", "verify", "version", "very", "vessel", "veteran", "viable", "vibrant", "vicious", "victory", "video", "view", "village", "vintage", "violin", "virtual", "virus", "visa", "visit", "visual", "vital", "vivid", "vocal", "voice", "void", "volcano", "volume", "vote", "voyage", "wage", "wagon", "wait", "walk", "wall", "walnut", "want", "warfare", "warm", "warrior", "wash", "wasp", "waste", "water", "wave", "way", "wealth", "weapon", "wear", "weasel", "weather", "web", "wedding", "weekend", "weird", "welcome", "west", "wet", "whale", "what", "wheat", "wheel", "when", "where", "whip", "whisper", "wide", "width", "wife", "wild", "will", "win", "window", "wine", "wing", "wink", "winner", "winter", "wire", "wisdom", "wise", "wish", "witness", "wolf", "woman", "wonder", "wood", "wool", "word", "work", "world", "worry", "worth", "wrap", "wreck", "wrestle", "wrist", "write", "wrong", "yard", "year", "ORANGE", "you", "young", "youth", "zebra", "zero", "zone", "zoo"] - -#seedphrase variables -seedphrase = ["word0", "word1", "word2", "word3", "word4", "word5", "word6", "word7", "word8", "word9", "word10", "word11", "word12", "word13", "word14", "word15", "word16", "word17", "word18", "word19", "word20", "word21", "word22", "word23"] -wordcounter = 1 -letterstate = 1 - -# initialize letters -letterslot1 = "a" -letterslot2 = "a" -letterslot3 = "a" -letterslot4 = "a" - -#accept the list output from each of the getletter functions -function1return = [] -function2return = [] -function3return = [] -function4return = [] - -#function to get previous letter -def getPrevLetter(letter): - number = alphabet.index(letter) - number = number - 1 - if number == -1: - number = 25 - return alphabet[number] - else: - return alphabet[number] - -#function to get next letter -def getNextLetter(letter): - number = alphabet.index(letter) - number = number + 1 - if number == 26: - number = 0 - return alphabet[number] - else: - return alphabet[number] - -# function to get FIRST letter -def getletter1(inputletter): - runstate = 1 - localletter = inputletter - global wordcounter - while runstate == 1: - draw.rectangle((0, 0, width, height), outline=0, fill=0) - draw.text((75, 2), "Seed Word: " + str(wordcounter), fill="ORANGE", font=impact18) - draw.text((15, 210), "(choose from words on right)", fill="ORANGE", font=impact18) - draw.text((5, 90), localletter, fill="ORANGE", font=impact35) - #time.sleep(0.2) - - if GPIO.input(KEY_UP_PIN) == GPIO.LOW: # button is released - time.sleep(0.1) - draw.polygon([(8, 85), (14, 69), (20, 85)], outline="ORANGE", fill="ORANGE") - #localletter = getPrevLetter(localletter) - else: # button is pressed: - draw.polygon([(8, 85), (14, 69), (20, 85)], outline="ORANGE", fill=0) - localletter = getNextLetter(localletter) - - if GPIO.input(KEY_DOWN_PIN) == GPIO.LOW: # button is released - time.sleep(0.1) - draw.polygon([(8, 148), (14, 164), (20, 148)], outline="ORANGE", fill="ORANGE") - #localletter = getNextLetter(localletter) - else: # button is pressed: - draw.polygon([(8, 148), (14, 164), (20, 148)], outline="ORANGE", fill=0) - localletter = getPrevLetter(localletter) - - if GPIO.input(KEY_RIGHT_PIN) == GPIO.LOW: # button is released - time.sleep(0.2) - nextslot = 2 - runstate = 0 - return [localletter, nextslot] - - if GPIO.input(KEY_LEFT_PIN) == GPIO.LOW: # button is released - time.sleep(0.2) - if wordcounter == 1: - nextslot = 0 - runstate = 0 - return [localletter, nextslot] - else: - wordcounter = wordcounter - 1 - nextslot = 1 - runstate = 0 - return [localletter, nextslot] - - possibles = [i for i in seedwords if i.startswith(localletter)] - if len(possibles) == 1: - word1width = impact25.getsize(possibles[0]) - offset1 = 223 - word1width[0] - draw.text((offset1, 39), possibles[0] + " -", fill="ORANGE", font=impact25) - elif len(possibles) == 2: - word1width = impact25.getsize(possibles[0]) - offset1 = 223 - word1width[0] - draw.text((offset1, 39), possibles[0] + " -", fill="ORANGE", font=impact25) - word2width = impact25.getsize(possibles[1]) - offset2 = 223 - word2width[0] - draw.text((offset2, 97), possibles[1] + " -", fill="ORANGE", font=impact25) - elif len(possibles) >= 3: - word1width = impact25.getsize(possibles[0]) - offset1 = 223 - word1width[0] - draw.text((offset1, 39), possibles[0] + " -", fill="ORANGE", font=impact25) - word2width = impact25.getsize(possibles[1]) - offset2 = 223 - word2width[0] - draw.text((offset2, 97), possibles[1] + " -", fill="ORANGE", font=impact25) - word3width = impact25.getsize(possibles[2]) - offset3 = 223 - word3width[0] - draw.text((offset3, 157), possibles[2] + " -", fill="ORANGE", font=impact25) - - if GPIO.input(KEY1_PIN) == GPIO.LOW: # button is released - time.sleep(0.2) - nextslot = 1 - selectedword = possibles[0] - seedphrase[wordcounter] = selectedword - wordcounter = wordcounter + 1 - runstate = 0 - return [localletter, nextslot] - - if GPIO.input(KEY2_PIN) == GPIO.LOW: # button is released - time.sleep(0.2) - nextslot = 1 - selectedword = possibles[1] - seedphrase[wordcounter] = selectedword - wordcounter = wordcounter + 1 - runstate = 0 - return [localletter, nextslot] - - if GPIO.input(KEY3_PIN) == GPIO.LOW: # button is released - time.sleep(0.2) - nextslot = 1 - selectedword = possibles[2] - seedphrase[wordcounter] = selectedword - wordcounter = wordcounter + 1 - runstate = 0 - return [localletter, nextslot] - - disp.ShowImage(image,0,0) - -#function to get SECOND letter -def getletter2(inputletter): - runstate = 1 #just defines whether the current function is still running - localletter = inputletter #gathers the letter from the function input - global wordcounter - while runstate == 1: - draw.rectangle((0, 0, width, height), outline=0, fill=0) - draw.text((75, 2), "Seed Word: " + str(wordcounter), fill="ORANGE", font=impact18) - draw.text((18, 210), "(choose from words on right)", fill="ORANGE", font=impact18) - draw.text((5, 90), letterslot1, fill="ORANGE", font=impact35) - draw.text((35, 90), localletter, fill="ORANGE", font=impact35) - #time.sleep(0.1) - - if GPIO.input(KEY_UP_PIN) == GPIO.LOW: # button is released - time.sleep(0.1) - draw.polygon([(38, 85), (44, 69), (50, 85)], outline="ORANGE", fill="ORANGE") - else: # button is pressed: - draw.polygon([(38, 85), (44, 69), (50, 85)], outline="ORANGE", fill=0) - localletter = getNextLetter(localletter) - - if GPIO.input(KEY_DOWN_PIN) == GPIO.LOW: # button is released - time.sleep(0.1) - draw.polygon([(38, 148), (44, 164), (50, 148)], outline="ORANGE", fill="ORANGE") - else: # button is pressed: - draw.polygon([(38, 148), (44, 164), (50, 148)], outline="ORANGE", fill=0) - localletter = getPrevLetter(localletter) - - if GPIO.input(KEY_LEFT_PIN) == GPIO.LOW: # button is released - time.sleep(0.2) - nextslot = 1 - runstate = 0 - return [localletter, nextslot] - - if GPIO.input(KEY_RIGHT_PIN) == GPIO.LOW: # button is released - time.sleep(0.2) - nextslot = 3 - runstate = 0 - return [localletter, nextslot] - - possibles = [i for i in seedwords if i.startswith(letterslot1 + localletter)] - if len(possibles) == 1: - word1width = impact25.getsize(possibles[0]) - offset1 = 223 - word1width[0] - draw.text((offset1, 39), possibles[0] + " -", fill="ORANGE", font=impact25) - elif len(possibles) == 2: - word1width = impact25.getsize(possibles[0]) - offset1 = 223 - word1width[0] - draw.text((offset1, 39), possibles[0] + " -", fill="ORANGE", font=impact25) - word2width = impact25.getsize(possibles[1]) - offset2 = 223 - word2width[0] - draw.text((offset2, 97), possibles[1] + " -", fill="ORANGE", font=impact25) - elif len(possibles) >= 3: - word1width = impact25.getsize(possibles[0]) - offset1 = 223 - word1width[0] - draw.text((offset1, 39), possibles[0] + " -", fill="ORANGE", font=impact25) - word2width = impact25.getsize(possibles[1]) - offset2 = 223 - word2width[0] - draw.text((offset2, 97), possibles[1] + " -", fill="ORANGE", font=impact25) - word3width = impact25.getsize(possibles[2]) - offset3 = 223 - word3width[0] - draw.text((offset3, 157), possibles[2] + " -", fill="ORANGE", font=impact25) - - if GPIO.input(KEY1_PIN) == GPIO.LOW: # button is released - time.sleep(0.2) - nextslot = 1 - selectedword = possibles[0] - seedphrase[wordcounter] = selectedword - wordcounter = wordcounter + 1 - runstate = 0 - return [localletter, nextslot] - - if GPIO.input(KEY2_PIN) == GPIO.LOW: # button is released - time.sleep(0.2) - nextslot = 1 - selectedword = possibles[1] - seedphrase[wordcounter] = selectedword - wordcounter = wordcounter + 1 - runstate = 0 - return [localletter, nextslot] - - if GPIO.input(KEY3_PIN) == GPIO.LOW: # button is released - time.sleep(0.2) - nextslot = 1 - selectedword = possibles[2] - seedphrase[wordcounter] = selectedword - wordcounter = wordcounter + 1 - runstate = 0 - return [localletter, nextslot] - - disp.ShowImage(image,0,0) - -#function to get THIRD letter -def getletter3(inputletter): - runstate = 1 - localletter = inputletter - global wordcounter - while runstate == 1: - draw.rectangle((0, 0, width, height), outline=0, fill=0) - draw.text((75, 2), "Seed Word: " + str(wordcounter), fill="ORANGE", font=impact18) - draw.text((18, 210), "(choose from words on right)", fill="ORANGE", font=impact18) - draw.text((5, 90), letterslot1, fill="ORANGE", font=impact35) - draw.text((35, 90), letterslot2, fill="ORANGE", font=impact35) - draw.text((65, 90), localletter, fill="ORANGE", font=impact35) - #time.sleep(0.1) - - if GPIO.input(KEY_UP_PIN) == GPIO.LOW: # button is released - time.sleep(0.1) - draw.polygon([(68, 85), (74, 69), (80, 85)], outline="ORANGE", fill="ORANGE") - else: # button is pressed: - draw.polygon([(68, 85), (74, 69), (80, 85)], outline="ORANGE", fill=0) - localletter = getNextLetter(localletter) - - if GPIO.input(KEY_DOWN_PIN) == GPIO.LOW: # button is released - time.sleep(0.1) - draw.polygon([(68, 148), (74, 162), (80, 148)], outline="ORANGE", fill="ORANGE") - else: # button is pressed: - draw.polygon([(68, 148), (74, 162), (80, 148)], outline="ORANGE", fill=0) - localletter = getPrevLetter(localletter) - - if GPIO.input(KEY_LEFT_PIN) == GPIO.LOW: # button is released - time.sleep(0.2) - nextslot = 2 - runstate = 0 - return [localletter, nextslot] - - if GPIO.input(KEY_RIGHT_PIN) == GPIO.LOW: # button is released - time.sleep(0.2) - nextslot = 4 - runstate = 0 - return [localletter, nextslot] - - possibles = [i for i in seedwords if i.startswith(letterslot1 + letterslot2 + localletter)] - if len(possibles) == 1: - word1width = impact25.getsize(possibles[0]) - offset1 = 223 - word1width[0] - draw.text((offset1, 39), possibles[0] + " -", fill="ORANGE", font=impact25) - elif len(possibles) == 2: - word1width = impact25.getsize(possibles[0]) - offset1 = 223 - word1width[0] - draw.text((offset1, 39), possibles[0] + " -", fill="ORANGE", font=impact25) - word2width = impact25.getsize(possibles[1]) - offset2 = 223 - word2width[0] - draw.text((offset2, 97), possibles[1] + " -", fill="ORANGE", font=impact25) - elif len(possibles) >= 3: - word1width = impact25.getsize(possibles[0]) - offset1 = 223 - word1width[0] - draw.text((offset1, 39), possibles[0] + " -", fill="ORANGE", font=impact25) - word2width = impact25.getsize(possibles[1]) - offset2 = 223 - word2width[0] - draw.text((offset2, 97), possibles[1] + " -", fill="ORANGE", font=impact25) - word3width = impact25.getsize(possibles[2]) - offset3 = 223 - word3width[0] - draw.text((offset3, 157), possibles[2] + " -", fill="ORANGE", font=impact25) - - if GPIO.input(KEY1_PIN) == GPIO.LOW: # button is released - time.sleep(0.2) - nextslot = 1 - selectedword = possibles[0] - seedphrase[wordcounter] = selectedword - wordcounter = wordcounter + 1 - runstate = 0 - return [localletter, nextslot] - - if GPIO.input(KEY2_PIN) == GPIO.LOW: # button is released - time.sleep(0.2) - nextslot = 1 - selectedword = possibles[1] - seedphrase[wordcounter] = selectedword - wordcounter = wordcounter + 1 - runstate = 0 - return [localletter, nextslot] - - if GPIO.input(KEY3_PIN) == GPIO.LOW: # button is released - time.sleep(0.2) - nextslot = 1 - selectedword = possibles[2] - seedphrase[wordcounter] = selectedword - wordcounter = wordcounter + 1 - runstate = 0 - return [localletter, nextslot] - - disp.ShowImage(image,0,0) - -#function to get FOURTH letter -def getletter4(inputletter): - runstate = 1 - localletter = inputletter - global wordcounter - while runstate == 1: - draw.rectangle((0, 0, width, height), outline=0, fill=0) - draw.text((75, 2), "Seed Word: " + str(wordcounter), fill="ORANGE", font=impact18) - draw.text((18, 210), "(choose from words on right)", fill="ORANGE", font=impact18) - draw.text((5, 90), letterslot1, fill="ORANGE", font=impact35) - draw.text((35, 90), letterslot2, fill="ORANGE", font=impact35) - draw.text((65, 90), letterslot3, fill="ORANGE", font=impact35) - draw.text((95, 90), localletter, fill="ORANGE", font=impact35) - #time.sleep(0.1) - - if GPIO.input(KEY_UP_PIN) == GPIO.LOW: # button is released - time.sleep(0.1) - draw.polygon([(98, 85), (104, 69), (110, 85)], outline="ORANGE", fill="ORANGE") - else: # button is pressed: - draw.polygon([(98, 85), (104, 69), (110, 85)], outline="ORANGE", fill=0) - localletter = getNextLetter(localletter) - - if GPIO.input(KEY_DOWN_PIN) == GPIO.LOW: # button is released - time.sleep(0.1) - draw.polygon([(98, 148), (104, 162), (110, 148)], outline="ORANGE", fill="ORANGE") - else: # button is pressed: - draw.polygon([(98, 148), (104, 162), (110, 148)], outline="ORANGE", fill=0) - localletter = getPrevLetter(localletter) - - if GPIO.input(KEY_LEFT_PIN) == GPIO.LOW: # button is released - time.sleep(0.2) - nextslot = 3 - runstate = 0 - return [localletter, nextslot] - - #nothing should happen if right is pressed on fourth letter - #if GPIO.input(KEY_RIGHT_PIN) == GPIO.LOW: # button is released - #time.sleep(0.1) - #nextslot = 0 - #runstate = 0 - #return [localletter, nextslot] - - possibles = [i for i in seedwords if i.startswith(letterslot1 + letterslot2 + letterslot3 + localletter)] - if len(possibles) == 1: - word1width = impact25.getsize(possibles[0]) - offset1 = 223 - word1width[0] - draw.text((offset1, 39), possibles[0] + " -", fill="ORANGE", font=impact25) - elif len(possibles) == 2: - word1width = impact25.getsize(possibles[0]) - offset1 = 223 - word1width[0] - draw.text((offset1, 39), possibles[0] + " -", fill="ORANGE", font=impact25) - word2width = impact25.getsize(possibles[1]) - offset2 = 223 - word2width[0] - draw.text((offset2, 97), possibles[1] + " -", fill="ORANGE", font=impact25) - elif len(possibles) >= 3: - word1width = impact25.getsize(possibles[0]) - offset1 = 223 - word1width[0] - draw.text((offset1, 39), possibles[0] + " -", fill="ORANGE", font=impact25) - word2width = impact25.getsize(possibles[1]) - offset2 = 223 - word2width[0] - draw.text((offset2, 97), possibles[1] + " -", fill="ORANGE", font=impact25) - word3width = impact25.getsize(possibles[2]) - offset3 = 223 - word3width[0] - draw.text((offset3, 157), possibles[2] + " -", fill="ORANGE", font=impact25) - - if GPIO.input(KEY1_PIN) == GPIO.LOW: # button is released - time.sleep(0.2) - nextslot = 1 - selectedword = possibles[0] - seedphrase[wordcounter] = selectedword - wordcounter = wordcounter + 1 - runstate = 0 - return [localletter, nextslot] - - if GPIO.input(KEY2_PIN) == GPIO.LOW: # button is released - time.sleep(0.2) - nextslot = 1 - selectedword = possibles[1] - seedphrase[wordcounter] = selectedword - wordcounter = wordcounter + 1 - runstate = 0 - return [localletter, nextslot] - - if GPIO.input(KEY3_PIN) == GPIO.LOW: # button is released - time.sleep(0.2) - nextslot = 1 - selectedword = possibles[2] - seedphrase[wordcounter] = selectedword - wordcounter = wordcounter + 1 - runstate = 0 - return [localletter, nextslot] - - disp.ShowImage(image,0,0) - -def getword(): - global letterslot1 - global letterslot2 - global letterslot3 - global letterslot4 - global wordcounter - global letterstate - print("the wordcounter is at: ", wordcounter) - - #defines the which letter is being currently gathered - #letterstate = 1 - allowedletterstates = [0, 1, 2, 3, 4] - - #manages the movement between the letter entry slots - print("the current letterstate is: ", letterstate) - while letterstate in allowedletterstates: - print("the current letterstate is: ", letterstate) - if letterstate == 0: - print("the letterstate was zero") - wordcounter = 0 - letterslot1 = "a" - letterslot2 = "a" - letterslot3 = "a" - letterslot4 = "a" - letterstate = 1 - return - if letterstate == 1: - letterslot1 = "a" - letterslot2 = "a" - letterslot3 = "a" - letterslot4 = "a" - function1return = getletter1(letterslot1) - letterslot1 = function1return[0] - letterstate = function1return[1] - elif letterstate == 2: - function2return = getletter2(letterslot2) - letterslot2 = function2return[0] - letterstate = function2return[1] - elif letterstate == 3: - function3return = getletter3(letterslot3) - letterslot3 = function3return[0] - letterstate = function3return[1] - elif letterstate == 4: - function4return = getletter4(letterslot4) - letterslot4 = function4return[0] - letterstate = function4return[1] - # letterslot1 = "a" - # letterslot2 = "a" - # letterslot3 = "a" - # letterslot4 = "a" - return - - letterslot1 = "a" - letterslot2 = "a" - letterslot3 = "a" - letterslot4 = "a" - letterstate = 1 - - - -def showverify_11(): - draw.rectangle((0, 0, width, height), outline=0, fill=0) - - textwidth, textheight = draw.textsize("Selected Words", font=impact18) - draw.text(((240 - textwidth) / 2, 2), "Selected Words", fill="ORANGE", font=impact18) - draw.text((2, 40), "1: " + seedphrase[1], fill="ORANGE", font=impact23) - draw.text((2, 65), "2: " + seedphrase[2], fill="ORANGE", font=impact23) - draw.text((2, 90), "3: " + seedphrase[3], fill="ORANGE", font=impact23) - draw.text((2, 115), "4: " + seedphrase[4], fill="ORANGE", font=impact23) - draw.text((2, 140), "5: " + seedphrase[5], fill="ORANGE", font=impact23) - draw.text((2, 165), "6: " + seedphrase[6], fill="ORANGE", font=impact23) - draw.text((120, 40), "7: " + seedphrase[7], fill="ORANGE", font=impact23) - draw.text((120, 65), "8: " + seedphrase[8], fill="ORANGE", font=impact23) - draw.text((120, 90), "9: " + seedphrase[9], fill="ORANGE", font=impact23) - draw.text((120, 115), "10: " + seedphrase[10], fill="ORANGE", font=impact23) - draw.text((120, 140), "11: " + seedphrase[11], fill="ORANGE", font=impact23) - draw.text((65, 210), "RIGHT to verify", fill="ORANGE", font=impact18) - - disp.ShowImage(image, 0, 0) - -def gather_11_words(runstate): - global seedphrase - global wordcounter - - localrunstate = runstate - - allowedwordstates = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] - - while wordcounter in allowedwordstates: - print("according to gather_11_words, the wordcounter is at: ", wordcounter) - getword() - letterslot1 = "a" - letterslot2 = "a" - letterslot3 = "a" - letterslot4 = "a" - #print(seedphrase) - - if wordcounter == 0: - localrunstate[0] = 0 - localrunstate[1] = "" - seedphrase = ["word0", "word1", "word2", "word3", "word4", "word5", "word6", "word7", "word8", "word9", - "word10", - "word11", "word12", "word13", "word14", "word15", "word16", "word17", "word18", "word19", - "word20", - "word21", "word22", "word23"] - wordcounter = 1 - return localrunstate - - verify1runstate = 1 - while verify1runstate == 1: - showverify_11() - if GPIO.input(KEY_RIGHT_PIN) == GPIO.LOW: # button is released - time.sleep(0.2) - verify1runstate = 0 - - seedphrase.pop(0) - localrunstate[1] = " ".join(seedphrase[0:11:]) - - localrunstate[0] = 52 - - seedphrase = ["word0", "word1", "word2", "word3", "word4", "word5", "word6", "word7", "word8", "word9", "word10", - "word11", "word12", "word13", "word14", "word15", "word16", "word17", "word18", "word19", "word20", - "word21", "word22", "word23"] - wordcounter = 1 - - print("End of Gather 11 Words") - - return localrunstate - -def showverify_23_1(): - draw.rectangle((0, 0, width, height), outline=0, fill=0) - - draw.text((40, 2), "Selected Words (1/2)", fill="ORANGE", font=impact18) - draw.text((2, 40), "1: " + seedphrase[1], fill="ORANGE", font=impact23) - draw.text((2, 65), "2: " + seedphrase[2], fill="ORANGE", font=impact23) - draw.text((2, 90), "3: " + seedphrase[3], fill="ORANGE", font=impact23) - draw.text((2, 115), "4: " + seedphrase[4], fill="ORANGE", font=impact23) - draw.text((2, 140), "5: " + seedphrase[5], fill="ORANGE", font=impact23) - draw.text((2, 165), "6: " + seedphrase[6], fill="ORANGE", font=impact23) - draw.text((120, 40), " 7: " + seedphrase[7], fill="ORANGE", font=impact23) - draw.text((120, 65), " 8: " + seedphrase[8], fill="ORANGE", font=impact23) - draw.text((120, 90), " 9: " + seedphrase[9], fill="ORANGE", font=impact23) - draw.text((120, 115), "10: " + seedphrase[10], fill="ORANGE", font=impact23) - draw.text((120, 140), "11: " + seedphrase[11], fill="ORANGE", font=impact23) - draw.text((120, 165), "12: " + seedphrase[12], fill="ORANGE", font=impact23) - draw.text((65, 210), "RIGHT to verify", fill="ORANGE", font=impact18) - - disp.ShowImage(image,0,0) - -def showverify_23_2(): - draw.rectangle((0, 0, width, height), outline=0, fill=0) - - draw.text((40, 2), "Selected Words (2/2)", fill="ORANGE", font=impact18) - draw.text((2, 40), "13: " + seedphrase[13], fill="ORANGE", font=impact23) - draw.text((2, 65), "14: " + seedphrase[14], fill="ORANGE", font=impact23) - draw.text((2, 90), "15: " + seedphrase[15], fill="ORANGE", font=impact23) - draw.text((2, 115), "16: " + seedphrase[16], fill="ORANGE", font=impact23) - draw.text((2, 140), "17: " + seedphrase[17], fill="ORANGE", font=impact23) - draw.text((2, 165), "18: " + seedphrase[18], fill="ORANGE", font=impact23) - draw.text((120, 40), "19: " + seedphrase[19], fill="ORANGE", font=impact23) - draw.text((120, 65), "20: " + seedphrase[20], fill="ORANGE", font=impact23) - draw.text((120, 90), "21: " + seedphrase[21], fill="ORANGE", font=impact23) - draw.text((120, 115), "22: " + seedphrase[22], fill="ORANGE", font=impact23) - draw.text((120, 140), "23: " + seedphrase[23], fill="ORANGE", font=impact23) - draw.text((65, 210), "RIGHT to verify", fill="ORANGE", font=impact18) - - disp.ShowImage(image, 0, 0) - -def gather_23_words(runstate): - global seedphrase - global wordcounter - - localrunstate = runstate - - allowedwordstates = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23] - - while wordcounter in allowedwordstates: - getword() - letterslot1 = "a" - letterslot2 = "a" - letterslot3 = "a" - letterslot4 = "a" - #print(seedphrase) - - if wordcounter == 0: - localrunstate[0] = 0 - localrunstate[1] = "" - seedphrase = ["word0", "word1", "word2", "word3", "word4", "word5", "word6", "word7", "word8", "word9", - "word10", - "word11", "word12", "word13", "word14", "word15", "word16", "word17", "word18", "word19", - "word20", - "word21", "word22", "word23"] - wordcounter = 1 - return localrunstate - - verify1runstate = 1 - while verify1runstate == 1: - showverify_23_1() - if GPIO.input(KEY_RIGHT_PIN) == GPIO.LOW: # button is released - time.sleep(0.1) - verify1runstate = 0 - - verify2runstate = 1 - while verify2runstate == 1: - showverify_23_2() - if GPIO.input(KEY_RIGHT_PIN) == GPIO.LOW: # button is released - time.sleep(0.1) - verify2runstate = 0 - - seedphrase.pop(0) - localrunstate[1] = " ".join(seedphrase) - - localrunstate[0] = 52 - - seedphrase = ["word0", "word1", "word2", "word3", "word4", "word5", "word6", "word7", "word8", "word9", "word10", - "word11", "word12", "word13", "word14", "word15", "word16", "word17", "word18", "word19", "word20", - "word21", "word22", "word23"] - wordcounter = 1 - - print("End of Gather 23 Words") - - return localrunstate - -def get_pre_calc_words(runstate): - localrunstate = runstate - - seedsize = numofwords_menu() - - if seedsize == "abort": - localrunstate[0] = 0 - localrunstate[1] = "" - return localrunstate - if seedsize == 12: - localrunstate[0] = 60 - return localrunstate - if seedsize == 24: - localrunstate[0] = 59 - return localrunstate - -def showverify_12(): - draw.rectangle((0, 0, width, height), outline=0, fill=0) - - textwidth, textheight = draw.textsize("Selected Words", font=impact18) - draw.text(((240 - textwidth) / 2, 2), "Selected Words", fill="ORANGE", font=impact18) - draw.text((2, 40), "1: " + seedphrase[1], fill="ORANGE", font=impact23) - draw.text((2, 65), "2: " + seedphrase[2], fill="ORANGE", font=impact23) - draw.text((2, 90), "3: " + seedphrase[3], fill="ORANGE", font=impact23) - draw.text((2, 115), "4: " + seedphrase[4], fill="ORANGE", font=impact23) - draw.text((2, 140), "5: " + seedphrase[5], fill="ORANGE", font=impact23) - draw.text((2, 165), "6: " + seedphrase[6], fill="ORANGE", font=impact23) - draw.text((120, 40), " 7: " + seedphrase[7], fill="ORANGE", font=impact23) - draw.text((120, 65), " 8: " + seedphrase[8], fill="ORANGE", font=impact23) - draw.text((120, 90), " 9: " + seedphrase[9], fill="ORANGE", font=impact23) - draw.text((120, 115), "10: " + seedphrase[10], fill="ORANGE", font=impact23) - draw.text((120, 140), "11: " + seedphrase[11], fill="ORANGE", font=impact23) - draw.text((120, 165), "12: " + seedphrase[12], fill="ORANGE", font=impact23) - draw.text((25, 210), "LEFT to EXIT, RIGHT to VERIFY", fill="ORANGE", font=impact18) - - disp.ShowImage(image,0,0) - -def showverify_24_1(): - draw.rectangle((0, 0, width, height), outline=0, fill=0) - - draw.text((40, 2), "Selected Words (1/2)", fill="ORANGE", font=impact18) - draw.text((2, 40), "1: " + seedphrase[1], fill="ORANGE", font=impact23) - draw.text((2, 65), "2: " + seedphrase[2], fill="ORANGE", font=impact23) - draw.text((2, 90), "3: " + seedphrase[3], fill="ORANGE", font=impact23) - draw.text((2, 115), "4: " + seedphrase[4], fill="ORANGE", font=impact23) - draw.text((2, 140), "5: " + seedphrase[5], fill="ORANGE", font=impact23) - draw.text((2, 165), "6: " + seedphrase[6], fill="ORANGE", font=impact23) - draw.text((120, 40), " 7: " + seedphrase[7], fill="ORANGE", font=impact23) - draw.text((120, 65), " 8: " + seedphrase[8], fill="ORANGE", font=impact23) - draw.text((120, 90), " 9: " + seedphrase[9], fill="ORANGE", font=impact23) - draw.text((120, 115), "10: " + seedphrase[10], fill="ORANGE", font=impact23) - draw.text((120, 140), "11: " + seedphrase[11], fill="ORANGE", font=impact23) - draw.text((120, 165), "12: " + seedphrase[12], fill="ORANGE", font=impact23) - draw.text((25, 210), "LEFT to EXIT, RIGHT to VERIFY", fill="ORANGE", font=impact18) - - disp.ShowImage(image,0,0) - -def showverify_24_2(): - draw.rectangle((0, 0, width, height), outline=0, fill=0) - - draw.text((40, 2), "Selected Words (2/2)", fill="ORANGE", font=impact18) - draw.text((2, 40), "13: " + seedphrase[13], fill="ORANGE", font=impact23) - draw.text((2, 65), "14: " + seedphrase[14], fill="ORANGE", font=impact23) - draw.text((2, 90), "15: " + seedphrase[15], fill="ORANGE", font=impact23) - draw.text((2, 115), "16: " + seedphrase[16], fill="ORANGE", font=impact23) - draw.text((2, 140), "17: " + seedphrase[17], fill="ORANGE", font=impact23) - draw.text((2, 165), "18: " + seedphrase[18], fill="ORANGE", font=impact23) - draw.text((120, 40), "19: " + seedphrase[19], fill="ORANGE", font=impact23) - draw.text((120, 65), "20: " + seedphrase[20], fill="ORANGE", font=impact23) - draw.text((120, 90), "21: " + seedphrase[21], fill="ORANGE", font=impact23) - draw.text((120, 115), "22: " + seedphrase[22], fill="ORANGE", font=impact23) - draw.text((120, 140), "23: " + seedphrase[23], fill="ORANGE", font=impact23) - draw.text((120, 165), "24: " + seedphrase[24], fill="ORANGE", font=impact23) - draw.text((25, 210), "LEFT to EXIT, RIGHT to VERIFY", fill="ORANGE", font=impact18) - - disp.ShowImage(image, 0, 0) - -def gather_12_words(runstate): - global seedphrase - global wordcounter - - seedphrase = ["word0", "word1", "word2", "word3", "word4", "word5", "word6", "word7", "word8", "word9", "word10", - "word11", "word12", "word13", "word14", "word15", "word16", "word17", "word18", "word19", "word20", - "word21", "word22", "word23", "word24"] - - localrunstate = runstate - - print("Runstate at the begining of gather_24_words is:") - print(localrunstate) - - allowedwordstates = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] - - while wordcounter in allowedwordstates: - getword() - letterslot1 = "a" - letterslot2 = "a" - letterslot3 = "a" - letterslot4 = "a" - #print(seedphrase) - - print("exited the wordcounter and the wordocunter is ", wordcounter) - if wordcounter == 0: - localrunstate[0] = 0 - localrunstate[1] = "" - seedphrase = ["word0", "word1", "word2", "word3", "word4", "word5", "word6", "word7", "word8", "word9", - "word10", - "word11", "word12", "word13", "word14", "word15", "word16", "word17", "word18", "word19", - "word20", - "word21", "word22", "word23"] - wordcounter = 1 - print("reached the end of the wordcounter is zero if statement") - print(localrunstate) - return localrunstate - - print(" ".join(seedphrase[1:13:])) - - draw.rectangle((0, 0, width, height), outline=0, fill=0) - textwidth, textheight = draw.textsize("Checking Seed Phrase...", font=impact22) - draw.text(((240 - textwidth) / 2, 100), "Checking Seed Phrase...", fill="ORANGE", font=impact22) - disp.ShowImage(image, 0, 0) - - try: - seedtest = bip39.mnemonic_to_seed(" ".join(seedphrase[1:13:])) - except ValueError: - print("Now that was one bad seed...") - - errormessagedisplayed = True - while errormessagedisplayed == True: - line1 = "Seed Appears Invalid" - line2 = "Check your seed" - line3 = "And try again" - line4 = "(Joystick RIGHT to EXIT)" - - draw.rectangle((0, 0, width, height), outline=0, fill=0) - textwidth, textheight = draw.textsize(line1, font=impact22) - draw.text(((240 - textwidth) / 2, 20), line1, fill="ORANGE", font=impact22) - textwidth, textheight = draw.textsize(line2, font=impact22) - draw.text(((240 - textwidth) / 2, 90), line2, fill="ORANGE", font=impact22) - textwidth, textheight = draw.textsize(line3, font=impact22) - draw.text(((240 - textwidth) / 2, 125), line3, fill="ORANGE", font=impact22) - textwidth, textheight = draw.textsize(line4, font=impact18) - draw.text(((240 - textwidth) / 2, 210), line4, fill="ORANGE", font=impact18) - disp.ShowImage(image, 0, 0) - - if GPIO.input(KEY_RIGHT_PIN) == GPIO.LOW: - time.sleep(0.4) - errormessagedisplayed = False - - wordcounter = 1 - localrunstate[0] = 0 - localrunstate[1] = "" - - print("Found an error in the seed and the runstate is:") - print(runstate) - - return localrunstate - - verify1runstate = 1 - while verify1runstate == 1: - showverify_12() - if GPIO.input(KEY_RIGHT_PIN) == GPIO.LOW: # button is released - time.sleep(0.2) - verify1runstate = 0 - if GPIO.input(KEY_LEFT_PIN) == GPIO.LOW: # button is released - time.sleep(0.2) - wordcounter = 1 - localrunstate[0] = 0 - localrunstate[1] = "" - verify1runstate = 0 - return localrunstate - - seedphrase.pop(0) - localrunstate[1] = " ".join(seedphrase[0:12:]) - - #localrunstate[0] = 0 - - seedphrase = ["word0", "word1", "word2", "word3", "word4", "word5", "word6", "word7", "word8", "word9", "word10", - "word11", "word12", "word13", "word14", "word15", "word16", "word17", "word18", "word19", "word20", - "word21", "word22", "word23"] - wordcounter = 1 - - print("End of Gather 12 Words") - print(localrunstate) - - return localrunstate - -def gather_24_words(runstate): - global seedphrase - global wordcounter - - seedphrase = ["word0", "word1", "word2", "word3", "word4", "word5", "word6", "word7", "word8", "word9", "word10", - "word11", "word12", "word13", "word14", "word15", "word16", "word17", "word18", "word19", "word20", - "word21", "word22", "word23", "word24"] - - localrunstate = runstate - - print("Runstate at the begining of gather_24_words is:") - print(localrunstate) - - allowedwordstates = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24] - - while wordcounter in allowedwordstates: - getword() - letterslot1 = "a" - letterslot2 = "a" - letterslot3 = "a" - letterslot4 = "a" - #print(seedphrase) - - if wordcounter == 0: - localrunstate[0] = 0 - localrunstate[1] = "" - seedphrase = ["word0", "word1", "word2", "word3", "word4", "word5", "word6", "word7", "word8", "word9", - "word10", - "word11", "word12", "word13", "word14", "word15", "word16", "word17", "word18", "word19", - "word20", - "word21", "word22", "word23"] - wordcounter = 1 - return localrunstate - - print(" ".join(seedphrase[1:])) - - draw.rectangle((0, 0, width, height), outline=0, fill=0) - textwidth, textheight = draw.textsize("Checking Seed Phrase...", font=impact22) - draw.text(((240 - textwidth) / 2, 100), "Checking Seed Phrase...", fill="ORANGE", font=impact22) - disp.ShowImage(image, 0, 0) - - try: - seedtest = bip39.mnemonic_to_seed(" ".join(seedphrase[1:])) - except ValueError: - print("Now that was one bad seed...") - - errormessagedisplayed = True - while errormessagedisplayed == True: - line1 = "Seed Appears Invalid" - line2 = "Check your seed" - line3 = "And try again" - line4 = "(Joystick RIGHT to EXIT)" - - draw.rectangle((0, 0, width, height), outline=0, fill=0) - textwidth, textheight = draw.textsize(line1, font=impact22) - draw.text(((240 - textwidth) / 2, 20), line1, fill="ORANGE", font=impact22) - textwidth, textheight = draw.textsize(line2, font=impact22) - draw.text(((240 - textwidth) / 2, 90), line2, fill="ORANGE", font=impact22) - textwidth, textheight = draw.textsize(line3, font=impact22) - draw.text(((240 - textwidth) / 2, 125), line3, fill="ORANGE", font=impact22) - textwidth, textheight = draw.textsize(line4, font=impact18) - draw.text(((240 - textwidth) / 2, 210), line4, fill="ORANGE", font=impact18) - disp.ShowImage(image, 0, 0) - - if GPIO.input(KEY_RIGHT_PIN) == GPIO.LOW: - time.sleep(0.4) - errormessagedisplayed = False - - wordcounter = 1 - localrunstate[0] = 0 - localrunstate[1] = "" - - print("Found an error in the seed and the runstate is:") - print(runstate) - - return localrunstate - - verify1runstate = 1 - while verify1runstate == 1: - showverify_24_1() - if GPIO.input(KEY_RIGHT_PIN) == GPIO.LOW: # button is released - time.sleep(0.2) - verify1runstate = 0 - if GPIO.input(KEY_LEFT_PIN) == GPIO.LOW: # button is released - time.sleep(0.2) - wordcounter = 1 - localrunstate[0] = 0 - localrunstate[1] = "" - verify1runstate = 0 - return localrunstate - - verify2runstate = 1 - while verify2runstate == 1: - showverify_24_2() - if GPIO.input(KEY_RIGHT_PIN) == GPIO.LOW: # button is released - time.sleep(0.2) - verify2runstate = 0 - if GPIO.input(KEY_LEFT_PIN) == GPIO.LOW: # button is released - time.sleep(0.2) - wordcounter = 1 - localrunstate[0] = 0 - localrunstate[1] = "" - verify1runstate = 0 - return localrunstate - - seedphrase.pop(0) - localrunstate[1] = " ".join(seedphrase) - - #localrunstate[0] = 0 - - seedphrase = ["word0", "word1", "word2", "word3", "word4", "word5", "word6", "word7", "word8", "word9", "word10", - "word11", "word12", "word13", "word14", "word15", "word16", "word17", "word18", "word19", "word20", - "word21", "word22", "word23"] - wordcounter = 1 - - print("End of Gather 24 Words") - print(localrunstate) - - return localrunstate - -def get_pre_sign_words(): - - seedsize = numofwords_menu() - - if seedsize == "abort": - return "abort" - if seedsize == 12: - return 12 - if seedsize == 24: - return 24 - -def confirmseedsaved(): - global activeseedsaveslot - - confirmationrunning = True - while confirmationrunning == True: - draw.rectangle((0, 0, width, height), outline=0, fill=0) - textwidth, textheight = draw.textsize("Seed Saved in Slot " + str(activeseedsaveslot), font=impact18) - draw.text(((240 - textwidth) / 2, 110), "Seed Saved in Slot " + str(activeseedsaveslot), fill="ORANGE", font=impact18) - textwidth, textheight = draw.textsize("Press joystick RIGHT to EXIT", font=impact18) - draw.text(((240 - textwidth) / 2, 215), "Press joystick RIGHT to EXIT", fill="ORANGE", font=impact18) - disp.ShowImage(image, 0, 0) - if GPIO.input(KEY_RIGHT_PIN) == GPIO.LOW: # button is released - time.sleep(0.3) - confirmationrunning = False - -def tempsaveseed(runstate): - localrunstate = runstate - - print("the active seedsaveslot is:", activeseedsaveslot) - - localseedsize = get_pre_sign_words() - - if localseedsize == "abort": - localrunstate[0] = 0 - localrunstate[1] = "" - return localrunstate - if localseedsize == 12: - localrunstate = gather_12_words(localrunstate) - localrunstate[2][activeseedsaveslot - 1] = localrunstate[1] - if localrunstate[2][activeseedsaveslot - 1] != "": - confirmseedsaved() - localrunstate[1] = "" - localrunstate[0] = 0 - return localrunstate - if localseedsize == 24: - localrunstate = gather_24_words(localrunstate) - localrunstate[2][activeseedsaveslot - 1] = localrunstate[1] - if localrunstate[2][activeseedsaveslot - 1] != "": - confirmseedsaved() - localrunstate[1] = "" - localrunstate[0] = 0 - return localrunstate - -# GETLASTWORD MODULE -# GETLASTWORD MODULE -# GETLASTWORD MODULE - -def displayfinalword(word24): - draw.rectangle((0, 0, width, height), outline=0, fill=0) - - textwidth, textheight = draw.textsize("The final word is :", font=impact23) - draw.text(((240 - textwidth) / 2, 60), "The final word is :", fill="ORANGE", font=impact23) - textwidth, textheight = draw.textsize(word24, font=impact50) - draw.text(((240 - textwidth) / 2, 90), word24, fill="ORANGE", font=impact50) - - draw.text((73, 210), "RIGHT to EXIT", fill="ORANGE", font=impact18) - - disp.ShowImage(image, 0, 0) - -def get_final_word(runstate): - localrunstate = runstate - - stringphrase = localrunstate[1] + " abandon" - - bytes = mnemonic_to_bytes(stringphrase, ignore_checksum=True) - - finalseed = mnemonic_from_bytes(bytes) - - splitseed = finalseed.split() - - word24 = splitseed[-1] - - displayword24runstate = 1 - while displayword24runstate == 1: - displayfinalword(word24) - if GPIO.input(KEY_RIGHT_PIN) == GPIO.LOW: # button is released - time.sleep(0.1) - displayword24runstate = 0 - - localrunstate[0] = 0 - localrunstate[1] = "" - return localrunstate - -# BEGIN DICE MODULE -# BEGIN DICE MODULE -# BEGIN DICE MODULE - -def drawdi1selected(): - draw.rectangle((5, 50, 75, 120), outline="ORANGE", fill="ORANGE") - draw.ellipse([(34, 79), (46, 91)], outline="BLACK", fill="BLACK") - draw.rectangle((85, 50, 155, 120), outline="ORANGE", fill="BLACK") - draw.ellipse([(100, 60), (112, 72)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(128, 98), (140, 110)], outline="ORANGE", fill="ORANGE") - draw.rectangle((165, 50, 235, 120), outline="ORANGE", fill="BLACK") - draw.ellipse([(180, 60), (192, 72)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(194, 79), (206, 91)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(208, 98), (220, 110)], outline="ORANGE", fill="ORANGE") - draw.rectangle((5, 130, 75, 200), outline="ORANGE", fill="BLACK") - draw.ellipse([(20, 140), (32, 152)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(20, 174), (32, 186)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(48, 140), (60, 152)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(48, 174), (60, 186)], outline="ORANGE", fill="ORANGE") - draw.rectangle((85, 130, 155, 200), outline="ORANGE", fill="BLACK") - draw.ellipse([(100, 140), (112, 152)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(100, 178), (112, 190)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(114, 159), (126, 171)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(128, 140), (140, 152)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(128, 178), (140, 190)], outline="ORANGE", fill="ORANGE") - draw.rectangle((165, 130, 235, 200), outline="ORANGE", fill="BLACK") - draw.ellipse([(180, 140), (192, 152)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(180, 157), (192, 169)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(180, 174), (192, 186)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(208, 140), (220, 152)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(208, 157), (220, 169)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(208, 174), (220, 186)], outline="ORANGE", fill="ORANGE") - draw.text((18, 210), "Press Control Stick to Select", fill="ORANGE", font=impact18) - -def drawdi2selected(): - draw.rectangle((5, 50, 75, 120), outline="ORANGE", fill="BLACK") - draw.ellipse([(34, 79), (46, 91)], outline="ORANGE", fill="ORANGE") - draw.rectangle((85, 50, 155, 120), outline="ORANGE", fill="ORANGE") - draw.ellipse([(100, 60), (112, 72)], outline="BLACK", fill="BLACK") - draw.ellipse([(128, 98), (140, 110)], outline="BLACK", fill="BLACK") - draw.rectangle((165, 50, 235, 120), outline="ORANGE", fill="BLACK") - draw.ellipse([(180, 60), (192, 72)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(194, 79), (206, 91)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(208, 98), (220, 110)], outline="ORANGE", fill="ORANGE") - draw.rectangle((5, 130, 75, 200), outline="ORANGE", fill="BLACK") - draw.ellipse([(20, 140), (32, 152)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(20, 174), (32, 186)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(48, 140), (60, 152)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(48, 174), (60, 186)], outline="ORANGE", fill="ORANGE") - draw.rectangle((85, 130, 155, 200), outline="ORANGE", fill="BLACK") - draw.ellipse([(100, 140), (112, 152)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(100, 178), (112, 190)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(114, 159), (126, 171)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(128, 140), (140, 152)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(128, 178), (140, 190)], outline="ORANGE", fill="ORANGE") - draw.rectangle((165, 130, 235, 200), outline="ORANGE", fill="BLACK") - draw.ellipse([(180, 140), (192, 152)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(180, 157), (192, 169)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(180, 174), (192, 186)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(208, 140), (220, 152)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(208, 157), (220, 169)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(208, 174), (220, 186)], outline="ORANGE", fill="ORANGE") - draw.text((18, 210), "Press Control Stick to Select", fill="ORANGE", font=impact18) - -def drawdi3selected(): - draw.rectangle((5, 50, 75, 120), outline="ORANGE", fill="BLACK") - draw.ellipse([(34, 79), (46, 91)], outline="ORANGE", fill="ORANGE") - draw.rectangle((85, 50, 155, 120), outline="ORANGE", fill="BLACK") - draw.ellipse([(100, 60), (112, 72)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(128, 98), (140, 110)], outline="ORANGE", fill="ORANGE") - draw.rectangle((165, 50, 235, 120), outline="ORANGE", fill="ORANGE") - draw.ellipse([(180, 60), (192, 72)], outline="BLACK", fill="BLACK") - draw.ellipse([(194, 79), (206, 91)], outline="BLACK", fill="BLACK") - draw.ellipse([(208, 98), (220, 110)], outline="BLACK", fill="BLACK") - draw.rectangle((5, 130, 75, 200), outline="ORANGE", fill="BLACK") - draw.ellipse([(20, 140), (32, 152)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(20, 174), (32, 186)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(48, 140), (60, 152)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(48, 174), (60, 186)], outline="ORANGE", fill="ORANGE") - draw.rectangle((85, 130, 155, 200), outline="ORANGE", fill="BLACK") - draw.ellipse([(100, 140), (112, 152)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(100, 178), (112, 190)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(114, 159), (126, 171)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(128, 140), (140, 152)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(128, 178), (140, 190)], outline="ORANGE", fill="ORANGE") - draw.rectangle((165, 130, 235, 200), outline="ORANGE", fill="BLACK") - draw.ellipse([(180, 140), (192, 152)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(180, 157), (192, 169)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(180, 174), (192, 186)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(208, 140), (220, 152)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(208, 157), (220, 169)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(208, 174), (220, 186)], outline="ORANGE", fill="ORANGE") - draw.text((18, 210), "Press Control Stick to Select", fill="ORANGE", font=impact18) - -def drawdi4selected(): - draw.rectangle((5, 50, 75, 120), outline="ORANGE", fill="BLACK") - draw.ellipse([(34, 79), (46, 91)], outline="ORANGE", fill="ORANGE") - draw.rectangle((85, 50, 155, 120), outline="ORANGE", fill="BLACK") - draw.ellipse([(100, 60), (112, 72)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(128, 98), (140, 110)], outline="ORANGE", fill="ORANGE") - draw.rectangle((165, 50, 235, 120), outline="ORANGE", fill="BLACK") - draw.ellipse([(180, 60), (192, 72)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(194, 79), (206, 91)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(208, 98), (220, 110)], outline="ORANGE", fill="ORANGE") - draw.rectangle((5, 130, 75, 200), outline="ORANGE", fill="ORANGE") - draw.ellipse([(20, 140), (32, 152)], outline="BLACK", fill="BLACK") - draw.ellipse([(20, 174), (32, 186)], outline="BLACK", fill="BLACK") - draw.ellipse([(48, 140), (60, 152)], outline="BLACK", fill="BLACK") - draw.ellipse([(48, 174), (60, 186)], outline="BLACK", fill="BLACK") - draw.rectangle((85, 130, 155, 200), outline="ORANGE", fill="BLACK") - draw.ellipse([(100, 140), (112, 152)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(100, 178), (112, 190)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(114, 159), (126, 171)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(128, 140), (140, 152)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(128, 178), (140, 190)], outline="ORANGE", fill="ORANGE") - draw.rectangle((165, 130, 235, 200), outline="ORANGE", fill="BLACK") - draw.ellipse([(180, 140), (192, 152)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(180, 157), (192, 169)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(180, 174), (192, 186)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(208, 140), (220, 152)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(208, 157), (220, 169)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(208, 174), (220, 186)], outline="ORANGE", fill="ORANGE") - draw.text((18, 210), "Press Control Stick to Select", fill="ORANGE", font=impact18) - -def drawdi5selected(): - draw.rectangle((5, 50, 75, 120), outline="ORANGE", fill="BLACK") - draw.ellipse([(34, 79), (46, 91)], outline="ORANGE", fill="ORANGE") - draw.rectangle((85, 50, 155, 120), outline="ORANGE", fill="BLACK") - draw.ellipse([(100, 60), (112, 72)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(128, 98), (140, 110)], outline="ORANGE", fill="ORANGE") - draw.rectangle((165, 50, 235, 120), outline="ORANGE", fill="BLACK") - draw.ellipse([(180, 60), (192, 72)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(194, 79), (206, 91)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(208, 98), (220, 110)], outline="ORANGE", fill="ORANGE") - draw.rectangle((5, 130, 75, 200), outline="ORANGE", fill="BLACK") - draw.ellipse([(20, 140), (32, 152)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(20, 174), (32, 186)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(48, 140), (60, 152)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(48, 174), (60, 186)], outline="ORANGE", fill="ORANGE") - draw.rectangle((85, 130, 155, 200), outline="ORANGE", fill="ORANGE") - draw.ellipse([(100, 140), (112, 152)], outline="BLACK", fill="BLACK") - draw.ellipse([(100, 178), (112, 190)], outline="BLACK", fill="BLACK") - draw.ellipse([(114, 159), (126, 171)], outline="BLACK", fill="BLACK") - draw.ellipse([(128, 140), (140, 152)], outline="BLACK", fill="BLACK") - draw.ellipse([(128, 178), (140, 190)], outline="BLACK", fill="BLACK") - draw.rectangle((165, 130, 235, 200), outline="ORANGE", fill="BLACK") - draw.ellipse([(180, 140), (192, 152)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(180, 157), (192, 169)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(180, 174), (192, 186)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(208, 140), (220, 152)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(208, 157), (220, 169)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(208, 174), (220, 186)], outline="ORANGE", fill="ORANGE") - draw.text((18, 210), "Press Control Stick to Select", fill="ORANGE", font=impact18) - -def drawdi6selected(): - draw.rectangle((5, 50, 75, 120), outline="ORANGE", fill="BLACK") - draw.ellipse([(34, 79), (46, 91)], outline="ORANGE", fill="ORANGE") - draw.rectangle((85, 50, 155, 120), outline="ORANGE", fill="BLACK") - draw.ellipse([(100, 60), (112, 72)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(128, 98), (140, 110)], outline="ORANGE", fill="ORANGE") - draw.rectangle((165, 50, 235, 120), outline="ORANGE", fill="BLACK") - draw.ellipse([(180, 60), (192, 72)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(194, 79), (206, 91)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(208, 98), (220, 110)], outline="ORANGE", fill="ORANGE") - draw.rectangle((5, 130, 75, 200), outline="ORANGE", fill="BLACK") - draw.ellipse([(20, 140), (32, 152)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(20, 174), (32, 186)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(48, 140), (60, 152)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(48, 174), (60, 186)], outline="ORANGE", fill="ORANGE") - draw.rectangle((85, 130, 155, 200), outline="ORANGE", fill="BLACK") - draw.ellipse([(100, 140), (112, 152)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(100, 178), (112, 190)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(114, 159), (126, 171)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(128, 140), (140, 152)], outline="ORANGE", fill="ORANGE") - draw.ellipse([(128, 178), (140, 190)], outline="ORANGE", fill="ORANGE") - draw.rectangle((165, 130, 235, 200), outline="ORANGE", fill="ORANGE") - draw.ellipse([(180, 140), (192, 152)], outline="BLACK", fill="BLACK") - draw.ellipse([(180, 157), (192, 169)], outline="BLACK", fill="BLACK") - draw.ellipse([(180, 174), (192, 186)], outline="BLACK", fill="BLACK") - draw.ellipse([(208, 140), (220, 152)], outline="BLACK", fill="BLACK") - draw.ellipse([(208, 157), (220, 169)], outline="BLACK", fill="BLACK") - draw.ellipse([(208, 174), (220, 186)], outline="BLACK", fill="BLACK") - draw.text((18, 210), "Press Control Stick to Select", fill="ORANGE", font=impact18) - -def rollsobtainer(): - - rollnumber = 1 - rollcollectorstring = "" - currentdiselected = 1 - draw.rectangle((0, 0, width, height), outline=0, fill=0) - draw.text((45, 5), "Dice roll: " + str(rollnumber) + "/99", fill="ORANGE", font=impact26) - drawdi1selected() - - while rollnumber <= 99: - if GPIO.input(KEY_RIGHT_PIN) == GPIO.LOW: - time.sleep(0.15) - if currentdiselected == 2: - currentdiselected = 3 - drawdi3selected() - if currentdiselected == 1: - currentdiselected = 2 - drawdi2selected() - if currentdiselected == 5: - currentdiselected = 6 - drawdi6selected() - if currentdiselected == 4: - currentdiselected = 5 - drawdi5selected() - if GPIO.input(KEY_LEFT_PIN) == GPIO.LOW: - time.sleep(0.15) - if currentdiselected == 2: - currentdiselected = 1 - drawdi1selected() - if currentdiselected == 3: - currentdiselected = 2 - drawdi2selected() - if currentdiselected == 5: - currentdiselected = 4 - drawdi4selected() - if currentdiselected == 6: - currentdiselected = 5 - drawdi5selected() - if GPIO.input(KEY_DOWN_PIN) == GPIO.LOW: - time.sleep(0.15) - if currentdiselected == 1: - currentdiselected = 4 - drawdi4selected() - if currentdiselected == 2: - currentdiselected = 5 - drawdi5selected() - if currentdiselected == 3: - currentdiselected = 6 - drawdi6selected() - if GPIO.input(KEY_UP_PIN) == GPIO.LOW: - time.sleep(0.15) - if currentdiselected == 4: - currentdiselected = 1 - drawdi1selected() - if currentdiselected == 5: - currentdiselected = 2 - drawdi2selected() - if currentdiselected == 6: - currentdiselected = 3 - drawdi3selected() - if GPIO.input(KEY_PRESS_PIN) == GPIO.LOW: - draw.rectangle((0, 0, width, height), outline=0, fill=0) - time.sleep(0.15) - if currentdiselected == 6: - rollcollectorstring = rollcollectorstring + "0" - else: - rollcollectorstring = rollcollectorstring + str(currentdiselected) - print("The roll number is " + str(rollnumber) + " and the die selections are : " + rollcollectorstring) - rollnumber = rollnumber + 1 - if currentdiselected == 1: - drawdi1selected() - if currentdiselected == 2: - drawdi2selected() - if currentdiselected == 3: - drawdi3selected() - if currentdiselected == 4: - drawdi4selected() - if currentdiselected == 5: - drawdi5selected() - if currentdiselected == 6: - drawdi6selected() - if rollnumber < 100: - draw.text((45, 5), "Dice roll: " + str(rollnumber) + "/99", fill="ORANGE", font=impact26) - disp.ShowImage(image, 0, 0) - - return rollcollectorstring - - -def getseedfromdice(runstate): - localrunstate = runstate - - impact18 = ImageFont.truetype('/usr/share/fonts/truetype/msttcorefonts/Impact.ttf', 18) - impact23 = ImageFont.truetype('/usr/share/fonts/truetype/msttcorefonts/Impact.ttf', 23) - - collectedrolls = rollsobtainer() - - entropyinteger = int(collectedrolls, 6) - - rollsinbytes = entropyinteger.to_bytes(32, byteorder="little") - - baddicestring = mnemonic_from_bytes(rollsinbytes) - - wordarray = baddicestring.split() - - wordarray.pop(-1) - - laststring = " ".join(wordarray) + " abandon" - - lastbytes = mnemonic_to_bytes(laststring, ignore_checksum=True) - - correctedlaststring = mnemonic_from_bytes(lastbytes) - - displayarray = correctedlaststring.split() - - firstwordset = True - while firstwordset is True: - #Display the first 12 words - draw.rectangle((0, 0, width, height), outline=0, fill=0) - draw.text((55, 2), "Your Seed Is (1/2):", fill="ORANGE", font=impact18) - draw.text((2, 40), "1: " + displayarray[0], fill="ORANGE", font=impact23) - draw.text((2, 65), "2: " + displayarray[1], fill="ORANGE", font=impact23) - draw.text((2, 90), "3: " + displayarray[2], fill="ORANGE", font=impact23) - draw.text((2, 115), "4: " + displayarray[3], fill="ORANGE", font=impact23) - draw.text((2, 140), "5: " + displayarray[4], fill="ORANGE", font=impact23) - draw.text((2, 165), "6: " + displayarray[5], fill="ORANGE", font=impact23) - draw.text((120, 40), " 7: " + displayarray[6], fill="ORANGE", font=impact23) - draw.text((120, 65), " 8: " + displayarray[7], fill="ORANGE", font=impact23) - draw.text((120, 90), " 9: " + displayarray[8], fill="ORANGE", font=impact23) - draw.text((120, 115), "10: " + displayarray[9], fill="ORANGE", font=impact23) - draw.text((120, 140), "11: " + displayarray[10], fill="ORANGE", font=impact23) - draw.text((120, 165), "12: " + displayarray[11], fill="ORANGE", font=impact23) - draw.text((55, 210), "RIGHT to Continue", fill="ORANGE", font=impact18) - disp.ShowImage(image, 0, 0) - - if GPIO.input(KEY_RIGHT_PIN) == GPIO.LOW: - time.sleep(0.25) - firstwordset = False - - secondwordset = True - while secondwordset is True: - # Display the second 12 words - draw.rectangle((0, 0, width, height), outline=0, fill=0) - draw.text((55, 2), "Your Seed Is (2/2):", fill="ORANGE", font=impact18) - draw.text((2, 40), "13: " + displayarray[12], fill="ORANGE", font=impact23) - draw.text((2, 65), "14: " + displayarray[13], fill="ORANGE", font=impact23) - draw.text((2, 90), "15: " + displayarray[14], fill="ORANGE", font=impact23) - draw.text((2, 115), "16: " + displayarray[15], fill="ORANGE", font=impact23) - draw.text((2, 140), "17: " + displayarray[16], fill="ORANGE", font=impact23) - draw.text((2, 165), "18: " + displayarray[17], fill="ORANGE", font=impact23) - draw.text((120, 40), "19: " + displayarray[18], fill="ORANGE", font=impact23) - draw.text((120, 65), "20: " + displayarray[19], fill="ORANGE", font=impact23) - draw.text((120, 90), "21: " + displayarray[20], fill="ORANGE", font=impact23) - draw.text((120, 115), "22: " + displayarray[21], fill="ORANGE", font=impact23) - draw.text((120, 140), "23: " + displayarray[22], fill="ORANGE", font=impact23) - draw.text((120, 165), "24: " + displayarray[23], fill="ORANGE", font=impact23) - draw.text((70, 210), "RIGHT to EXIT", fill="ORANGE", font=impact18) - disp.ShowImage(image, 0, 0) - - if GPIO.input(KEY_RIGHT_PIN) == GPIO.LOW: - time.sleep(0.25) - secondwordset = False - - localrunstate[0] = 0 - localrunstate[1] = "" - - return localrunstate - -# XPUBMAKE MODULE -# XPUBMAKE MODULE -# XPUBMAKE MODULE - -def showqrcodes(xpubstring): - localxpubstring = xpubstring - - # draw.rectangle((0, 0, width, height), outline=0, fill=0) - # draw.text((20, 110), "Creating Animated QR Code...", fill="ORANGE", font=impact18) - # disp.ShowImage(image, 0, 0) - - qrdata = localxpubstring - - stringlength = len(qrdata) - - # print("The length of the string is: " + str(stringlength)) - numofchunks = (stringlength // 100) + 1 - staticnumofchunks = numofchunks - listcounter = 1 - - start = 0 - stop = 99 - chunklist = ["p" + str(listcounter) + "of" + str(staticnumofchunks) + " " + qrdata[start:stop]] - # print("The start is: " + str(start) + " and the end is: " + str(stop)) - print(chunklist[0]) - qrimagelist = [qrcode.make(chunklist[0]).resize((240, 240)).convert('RGB')] - - while numofchunks > 1: - start = start + 100 - stop = stop + 100 - if stop > stringlength: - stop = stringlength # - 1 - chunklist.append("p" + str(listcounter + 1) + "of" + str(staticnumofchunks) + " " + qrdata[start - 1:stop]) - print(chunklist[listcounter]) - qrimagelist.append(qrcode.make(chunklist[listcounter]).resize((240, 240)).convert('RGB')) - listcounter = listcounter + 1 - numofchunks = numofchunks - 1 - - showingqrs = True - displayedqr = 0 - - while showingqrs == True: - disp.ShowImage(qrimagelist[displayedqr], 0, 0) - time.sleep(0.3) - if displayedqr < staticnumofchunks - 1: - displayedqr = displayedqr + 1 - time.sleep(0.3) - else: - displayedqr = 0 - time.sleep(0.3) - if GPIO.input(KEY_RIGHT_PIN) == GPIO.LOW: # button is released - time.sleep(0.2) - showingqrs = False - else: - time.sleep(0.3) - -def make_xpub(runstate): - localrunstate = runstate - global hardened_derivation - global currentnetwork - - decidedonwhichwords = False - while decidedonwhichwords == False: - if "" == localrunstate[2][0] and "" == localrunstate[2][1] and "" == localrunstate[2][2]: - numwords = get_pre_sign_words() - if numwords == "abort": - localrunstate[0] = 0 - localrunstate[1] = "" - return localrunstate - if numwords == 12: - localrunstate = gather_12_words(localrunstate) - decidedonwhichwords = True - if numwords == 24: - localrunstate = gather_24_words(localrunstate) - decidedonwhichwords = True - else: - print("saved words were detected") - usesavedwords = decideifusesavedwords() - if usesavedwords == "yes": - localrunstate = seedselect_menu(localrunstate) - if localrunstate[0] == 0: - localrunstate[1] = "" - return localrunstate - localrunstate[1] = localrunstate[2][activeseedsaveslot - 1] - localrunstate[0] = 54 - decidedonwhichwords = True - if usesavedwords == "no": - numwords = get_pre_sign_words() - if numwords == "abort": - localrunstate[0] = 0 - localrunstate[1] = "" - return localrunstate - if numwords == 12: - localrunstate = gather_12_words(localrunstate) - decidedonwhichwords = True - if numwords == 24: - localrunstate = gather_24_words(localrunstate) - decidedonwhichwords = True - - print("Made it back to the make_xpub function and the runstate is:") - print(runstate) - - if localrunstate[0] == 0: - localrunstate[1] = "" - return localrunstate - - draw.rectangle((0, 0, width, height), outline=0, fill=0) - draw.text((20, 110), "Creating Animated QR Code", fill="ORANGE", font=impact18) - disp.ShowImage(image, 0, 0) - - seed = bip39.mnemonic_to_seed(localrunstate[1]) - - root = bip32.HDKey.from_seed(seed, version=NETWORKS[currentnetwork]["xprv"]) - - # first let's get the root fingerprint - fingerprint = root.child(0).fingerprint - #hardened_derivation = "m/48h/0h/0h/2h" - - # derive account according to bip84 - bip48_xprv = root.derive(hardened_derivation) - - # corresponding master public key: - bip48_xpub = bip48_xprv.to_public() - - xpubstring = "[%s%s]%s" % ( - hexlify(fingerprint).decode('utf-8'), - hardened_derivation[1:], - bip48_xpub.to_base58(NETWORKS[currentnetwork]["Zpub"])) - - print(xpubstring) - - showqrcodes(xpubstring) - - localrunstate[0] = 0 - localrunstate[1] = "" - - print(localrunstate) - - return localrunstate - -# BEGIN PSBTSIGN MODULE -# BEGIN PSBTSIGN MODULE -# BEGIN PSBTSIGN MODULE - -def scananimatedqr(): - # draw.rectangle((0, 0, width, height), outline=0, fill=0) - # disp.ShowImage(image, 0, 0) - - vs = VideoStream(usePiCamera=True).start() # For Pi Camera - time.sleep(2.0) - - listofstrings = ["empty"] - framestatuslist = ["-"] - framestatusstring = "" - camerarunning = True - gotnumofframes = False - totalchunks = 0 - - while gotnumofframes == False: - frame = vs.read() - frame = imutils.resize(frame, width=400) - barcodes = pyzbar.decode(frame) - for barcode in barcodes: - barcodeData = barcode.data.decode("utf-8") - string = barcodeData - print(string) - if string[4].isdigit() == True: - if string[5].isdigit() == True: - print("The total number of chunks is", string[4:6]) - totalchunks = int(string[4:6]) - else: - print("The total number of digits is", string[4:5]) - totalchunks = int(string[4:5]) - elif string[5].isdigit() == True: - if string[6].isdigit() == True: - print("The total number of chunks is", string[5:7]) - totalchunks = int(string[5:7]) - else: - print("The total number of digits is", string[5:6]) - totalchunks = int(string[5:6]) - - gotnumofframes = True - if GPIO.input(KEY_LEFT_PIN) == GPIO.LOW: # button is released - print("joystick pressed left") - time.sleep(0.3) - vs.stop() - return "abort" - - chunkcounter = totalchunks - 1 - while chunkcounter >= 1: - listofstrings.append("empty") - framestatuslist.append("-") - chunkcounter = chunkcounter - 1 - - print(listofstrings) - - print(framestatuslist) - - while camerarunning == True: - frame = vs.read() - frame = imutils.resize(frame, width=400) - barcodes = pyzbar.decode(frame) - for barcode in barcodes: - barcodeData = barcode.data.decode("utf-8") - string = barcodeData - if string[1].isdigit() == True: - if string[2].isdigit() == True: - currentframe = int(string[1:3]) - else: - currentframe = int(string[1]) - spacelocation = string.find(" ") + 1 - length = len(string) - trimmedstring = string[spacelocation:length] - listofstrings[currentframe - 1] = trimmedstring - framestatuslist[currentframe - 1] = "*" - print(framestatusstring.join(framestatuslist)) - draw.rectangle((0, 0, width, height), outline=0, fill=0) - textwidth, textheight = draw.textsize("Collecting QR Codes:", font=impact22) - draw.text(((240 - textwidth) / 2, 15), "Collecting QR Codes:", fill="ORANGE", font=impact22) - lines = textwrap.wrap(framestatusstring.join(framestatuslist), width=11) - yheight = 60 - for line in lines: - textwidth, textheight = draw.textsize(line, font=couriernew30) - draw.text(((240 - textwidth) / 2, yheight), line, fill="ORANGE", font=couriernew30) - yheight += 30 - textwidth, textheight = draw.textsize("Press joystick LEFT to ABORT", font=impact18) - draw.text(((240 - textwidth) / 2, 215), "Press joystick LEFT to ABORT", fill="ORANGE", font=impact18) - disp.ShowImage(image, 0, 0) - if "empty" not in listofstrings: - camerarunning = False - if GPIO.input(KEY_LEFT_PIN) == GPIO.LOW: # button is released - print("joystick pressed left") - time.sleep(0.3) - vs.stop() - return "abort" ## need to uncomment for final insert - - qrcodevalue = "" - vs.stop() - print(qrcodevalue.join(listofstrings)) - return qrcodevalue.join(listofstrings) ## need to uncomment for final insert - -def parse_multisig(sc): - """Takes a script and extracts m,n and pubkeys from it""" - # OP_m ... OP_n OP_CHECKMULTISIG - # check min size - if len(sc.data) < 37 or sc.data[-1] != 0xae: - raise ValueError("Not a multisig script") - m = sc.data[0] - 0x50 - if m < 1 or m > 16: - raise ValueError("Invalid multisig script") - n = sc.data[-2] - 0x50 - if n < m or n > 16: - raise ValueError("Invalid multisig script") - s = BytesIO(sc.data) - # drop first byte - s.read(1) - # read pubkeys - pubkeys = [] - for i in range(n): - char = s.read(1) - if char != b"\x21": - raise ValueError("Invlid pubkey") - pubkeys.append(ec.PublicKey.parse(s.read(33))) - # check that nothing left - if s.read() != sc.data[-2:]: - raise ValueError("Invalid multisig script") - return m, n, pubkeys - -def get_cosigners(pubkeys, derivations, xpubs): - """Returns xpubs used to derive pubkeys using global xpub field from psbt""" - cosigners = [] - for i, pubkey in enumerate(pubkeys): - if pubkey not in derivations: - raise ValueError("Missing derivation") - der = derivations[pubkey] - for xpub in xpubs: - origin_der = xpubs[xpub] - # check fingerprint - if origin_der.fingerprint == der.fingerprint: - # check derivation - last two indexes give pub from xpub - if origin_der.derivation == der.derivation[:-2]: - # check that it derives to pubkey actually - if xpub.derive(der.derivation[-2:]).key == pubkey: - # append strings so they can be sorted and compared - cosigners.append(xpub.to_base58()) - break - if len(cosigners) != len(pubkeys): - raise RuntimeError("Can't get all cosigners") - return sorted(cosigners) - -def get_policy(scope, scriptpubkey, xpubs): - """Parse scope and get policy""" - # we don't know the policy yet, let's parse it - script_type = scriptpubkey.script_type() - # p2sh can be either legacy multisig, or nested segwit multisig - # or nested segwit singlesig - if script_type == "p2sh": - if scope.witness_script is not None: - script_type = "p2sh-p2wsh" - elif scope.redeem_script is not None and scope.redeem_script.script_type() == "p2wpkh": - script_type = "p2sh-p2wpkh" - policy = { "type": script_type } - # expected multisig - if "p2wsh" in script_type and scope.witness_script is not None: - m, n, pubkeys = parse_multisig(scope.witness_script) - # check pubkeys are derived from cosigners - cosigners = get_cosigners(pubkeys, scope.bip32_derivations, xpubs) - policy.update({ - "m": m, "n": n, "cosigners": cosigners - }) - return policy - -def signtransaction(seedphrase, psbtstring): - localseedphrase = seedphrase - localpsbtstring = psbtstring - destinationaddress = "self-transfer" - global runstate - - global currentnetwork - global hardened_derivation - - print("Current network settings are: " + currentnetwork + " " + hardened_derivation) - - seed = bip39.mnemonic_to_seed(localseedphrase) - - root = bip32.HDKey.from_seed(seed, version=NETWORKS[currentnetwork]["xprv"]) #was excluded before - - # first let's get the root fingerprint - fingerprint = root.child(0).fingerprint - #hardened_derivation = "m/48h/0h/0h/2h" - # derive account according to bip84 - bip48_xprv = root.derive(hardened_derivation) - # corresponding master public key: - bip48_xpub = bip48_xprv.to_public() - print("[%s%s]%s" % ( - hexlify(fingerprint).decode('utf-8'), - hardened_derivation[1:], - bip48_xpub.to_base58()) - ) - - # parse psbt transaction - b64_psbt = localpsbtstring - print("took in psbt string") - # first convert it to binary - raw = a2b_base64(b64_psbt) - print("converted to binary") - # then parse - tx = psbt.PSBT.parse(raw) - - # Check inputs of the transaction and check that they use the same script type - # For multisig parsed policy will look like this: - # { script_type: p2wsh, cosigners: [xpubs strings], m: 2, n: 3} - policy = None - inp_amount = 0 - for inp in tx.inputs: - inp_amount += inp.witness_utxo.value - # get policy of the input - inp_policy = get_policy(inp, inp.witness_utxo.script_pubkey, tx.xpubs) - # if policy is None - assign current - if policy is None: - policy = inp_policy - # otherwise check that everything in the policy is the same - else: - # check policy is the same - if policy != inp_policy: - raise RuntimeError("Mixed inputs in the transaction") - - wallet = "Native Segwit " - if "p2sh-" in policy["type"]: - wallet = "Nested Segwit " - if "m" in policy: - wallet += "Multisig (%d of %d)" % (policy["m"], policy["n"]) - else: - wallet += "Single sig" - print("Spending from: %s" % wallet) - print("Input amount: %d sat" % inp_amount) - - # now go through outputs and check if they are change - spending = 0 - change = 0 - for i, out in enumerate(tx.outputs): - out_policy = get_policy(out, tx.tx.vout[i].script_pubkey, tx.xpubs) - is_change = False - # if policy is the same - probably change - if out_policy == policy: - # double-check that it's change - # we already checked in get_cosigners and parse_multisig - # that pubkeys are generated from cosigners, - # and witness script is corresponding multisig - # so we only need to check that scriptpubkey is generated from - # witness script - - # empty script by default - sc = script.Script(b"") - # multisig, we know witness script - if policy["type"] == "p2wsh": - sc = script.p2wsh(out.witness_script) - elif policy["type"] == "p2sh-p2wsh": - sc = script.p2sh(script.p2wsh(out.witness_script)) - # single-sig - elif "pkh" in policy["type"]: - if len(out.bip32_derivations.values()) > 0: - der = list(out.bip32_derivations.values())[0].derivation - my_pubkey = root.derive(der) - if policy["type"] == "p2wpkh": - sc = script.p2wpkh(my_pubkey) - elif policy["type"] == "p2sh-p2wpkh": - sc = script.p2sh(script.p2wpkh(my_pubkey)) - if sc.data == tx.tx.vout[i].script_pubkey.data: - is_change = True - if is_change: - change += tx.tx.vout[i].value - print("Change %d sats" % tx.tx.vout[i].value) - else: - spending += tx.tx.vout[i].value - print("Spending %d sats to %s" % (tx.tx.vout[i].value, tx.tx.vout[i].script_pubkey.address(NETWORKS[currentnetwork]))) - destinationaddress = tx.tx.vout[i].script_pubkey.address(NETWORKS[currentnetwork]) - - fee = inp_amount - change - spending - - print("Fee: %d sats" % fee) - - - #destinationaddress = out.script_pubkey.address(NETWORKS[currentnetwork]) - - #display transaction information - #sendingamount = totalspending - totalfee #my original code - displaytransactioninfo = True - while displaytransactioninfo == True: - draw.rectangle((0, 0, width, height), outline=0, fill=0) - textwidth, textheight = draw.textsize("Confirm last 13 chars", font=impact22) - draw.text(((240 - textwidth) / 2, 5), "Confirm last 13 chars", fill="ORANGE", font=impact22) - textwidth, textheight = draw.textsize("of the receiving address:", font=impact22) - draw.text(((240 - textwidth) / 2, 30), "of the receiving address:", fill="ORANGE", font=impact22) - textwidth, textheight = draw.textsize(destinationaddress[-13:], font=impact22) - draw.text(((240 - textwidth) / 2, 55), destinationaddress[-13:], fill="ORANGE", font=impact22) - textwidth, textheight = draw.textsize("Amount Sending:", font=impact22) - draw.text(((240 - textwidth) / 2, 90), "Amount Sending:", fill="ORANGE", font=impact22) - if spending == 0: - textwidth, textheight = draw.textsize("Self-Transfer (not parsed)", font=impact22) - draw.text(((240 - textwidth) / 2, 115), "Self-Transfer (not parsed)", fill="ORANGE", font=impact22) - else: - textwidth, textheight = draw.textsize(str(spending) + " satoshis", font=impact22) - draw.text(((240 - textwidth) / 2, 115), str(spending) + " satoshis", fill="ORANGE", font=impact22) - textwidth, textheight = draw.textsize("Plus a fee of:", font=impact22) - draw.text(((240 - textwidth) / 2, 150), "Plus a fee of:", fill="ORANGE", font=impact22) - textwidth, textheight = draw.textsize(str(fee) + " satoshis", font=impact22) - draw.text(((240 - textwidth) / 2, 175), str(fee) + " satoshis", fill="ORANGE", font=impact22) - textwidth, textheight = draw.textsize("Left to EXIT, Right to CONTINUE", font=impact18) - draw.text(((240 - textwidth) / 2, 215), "Left to EXIT, Right to CONTINUE", fill="ORANGE", font=impact18) - disp.ShowImage(image, 0, 0) - if GPIO.input(KEY_RIGHT_PIN) == GPIO.LOW: # button is released - time.sleep(0.2) - displaytransactioninfo = False - if GPIO.input(KEY_LEFT_PIN) == GPIO.LOW: # button is released - time.sleep(0.2) - displaytransactioninfo = False - return("abort") - - #update the status screen - draw.rectangle((0, 0, width, height), outline=0, fill=0) - draw.text((20, 25), "Creating Animated QR Code...", fill="ORANGE", font=impact18) - disp.ShowImage(image, 0, 0) - - # sign the transaction - tx.sign_with(root) - - #added section to trim psbt - trimmed_psbt = psbt.PSBT(tx.tx) - sigsEnd = 0 - for i, inp in enumerate(tx.inputs): - sigsEnd += len(list(inp.partial_sigs.keys())) - trimmed_psbt.inputs[i].partial_sigs = inp.partial_sigs - - #raw = tx.serialize() #commented this out for the trim change - raw = trimmed_psbt.serialize() - - # convert to base64 - b64_psbt = b2a_base64(raw) - # somehow b2a ends with \n... - if b64_psbt[-1:] == b"\n": - b64_psbt = b64_psbt[:-1] - # print - print("\nSigned transaction:") - print(b64_psbt.decode('utf-8')) - return b64_psbt.decode('utf-8') - -def showqrcodes(signedpsbt): - localsignedpsbt = signedpsbt - - qrdata = localsignedpsbt - - stringlength = len(qrdata) - - # print("The length of the string is: " + str(stringlength)) - numofchunks = (stringlength // 100) + 1 - staticnumofchunks = numofchunks - listcounter = 1 - - start = 0 - stop = 99 - chunklist = ["p" + str(listcounter) + "of" + str(staticnumofchunks) + " " + qrdata[start:stop]] - print(chunklist[0]) - qrimagelist = [qrcode.make(chunklist[0]).resize((240, 240)).convert('RGB')] - - # draw.rectangle((0, 0, width, height), outline=0, fill=0) - # draw.text((20, 25), "Creating Animated QR Code...", fill="ORANGE", font=impact18) - generatingqrstatuslist = [] - generatingqrstatusstring = "" - dashesneeded = numofchunks - while dashesneeded > 1: - generatingqrstatuslist.append("-") - dashesneeded = dashesneeded - 1 - # lines = textwrap.wrap(generatingqrstatusstring.join(generatingqrstatuslist), width=11) - # yheight = 60 - # for line in lines: - # textwidth, textheight = draw.textsize(line, font=couriernew30) - # draw.text(((240 - textwidth) / 2, yheight), line, fill="ORANGE", font=couriernew30) - # yheight += 30 - # disp.ShowImage(image, 0, 0) - print(generatingqrstatuslist) - - while numofchunks > 1: - draw.rectangle((0, 0, width, height), outline=0, fill=0) - draw.text((20, 25), "Creating Animated QR Code...", fill="ORANGE", font=impact18) - start = start + 100 - stop = stop + 100 - if stop > stringlength: - stop = stringlength # - 1 - chunklist.append("p" + str(listcounter + 1) + "of" + str(staticnumofchunks) + " " + qrdata[start - 1:stop]) - print(chunklist[listcounter]) - qrimagelist.append(qrcode.make(chunklist[listcounter]).resize((240, 240)).convert('RGB')) - listcounter = listcounter + 1 - numofchunks = numofchunks - 1 - generatingqrstatuslist[listcounter - 2] = "*" - lines = textwrap.wrap(generatingqrstatusstring.join(generatingqrstatuslist), width=11) - yheight = 60 - for line in lines: - textwidth, textheight = draw.textsize(line, font=couriernew30) - draw.text(((240 - textwidth) / 2, yheight), line, fill="ORANGE", font=couriernew30) - yheight += 30 - disp.ShowImage(image, 0, 0) - - showingqrs = True - displayedqr = 0 - - while showingqrs == True: - - #Awkward structure is to allow for listening for joystick right - disp.ShowImage(qrimagelist[displayedqr], 0, 0) - time.sleep(0.1) - if GPIO.input(KEY_RIGHT_PIN) == GPIO.LOW: # button is released - time.sleep(0.1) - showingqrs = False - else: - time.sleep(0.1) - - disp.ShowImage(qrimagelist[displayedqr], 0, 0) - time.sleep(0.1) - if GPIO.input(KEY_RIGHT_PIN) == GPIO.LOW: # button is released - time.sleep(0.1) - showingqrs = False - else: - time.sleep(0.1) - - disp.ShowImage(qrimagelist[displayedqr], 0, 0) - time.sleep(0.1) - if GPIO.input(KEY_RIGHT_PIN) == GPIO.LOW: # button is released - time.sleep(0.1) - showingqrs = False - else: - time.sleep(0.1) - - - if displayedqr < staticnumofchunks - 1: - displayedqr = displayedqr + 1 - #time.sleep(0.3) - else: - displayedqr = 0 - #time.sleep(0.3) - -def sign_psbt(runstate): - localrunstate = runstate - - decidedonwhichwords = False - while decidedonwhichwords == False: - if "" == localrunstate[2][0] and "" == localrunstate[2][1] and "" == localrunstate[2][2]: - numwords = get_pre_sign_words() - if numwords == "abort": - localrunstate[0] = 0 - localrunstate[1] = "" - return localrunstate - if numwords == 12: - localrunstate = gather_12_words(localrunstate) - decidedonwhichwords = True - print("I hit the if statement") - if localrunstate[0] == 0: - localrunstate[1] = "" - return localrunstate - if numwords == 24: - localrunstate = gather_24_words(localrunstate) - decidedonwhichwords = True - if localrunstate[0] == 0: - localrunstate[1] = "" - return localrunstate - else: - print("saved words were detected") - usesavedwords = decideifusesavedwords() - if usesavedwords == "yes": - localrunstate = seedselect_menu(localrunstate) - localrunstate[1] = localrunstate[2][activeseedsaveslot - 1] - localrunstate[0] = 55 - decidedonwhichwords = True - if usesavedwords == "no": - numwords = get_pre_sign_words() - if numwords == "abort": - localrunstate[0] = 0 - localrunstate[1] = "" - return localrunstate - if numwords == 12: - print("got to the magic point") - localrunstate = gather_12_words(localrunstate) - decidedonwhichwords = True - if localrunstate[0] == 0: - localrunstate[1] = "" - return localrunstate - if numwords == 24: - localrunstate = gather_24_words(localrunstate) - decidedonwhichwords = True - if localrunstate[0] == 0: - localrunstate[1] = "" - return localrunstate - - if localrunstate[1] == "": - numwords = get_pre_sign_words() - - if numwords == "abort": - localrunstate[0] = 0 - localrunstate[1] = "" - return localrunstate - if numwords == 12: - localrunstate = gather_12_words(localrunstate) - if numwords == 24: - localrunstate = gather_24_words(localrunstate) - - if localrunstate[0] == 0: - localrunstate[1] = "" - return localrunstate - - print("The selected seed is:") - print(localrunstate[1]) - print("") - - draw.rectangle((0, 0, width, height), outline=0, fill=0) - draw.text((20, 110), "Scan the Animated QR Code", fill="ORANGE", font=impact18) - textwidth, textheight = draw.textsize("Press joystick LEFT to ABORT", font=impact18) - draw.text(((240 - textwidth) / 2, 215), "Press joystick LEFT to ABORT", fill="ORANGE", font=impact18) - disp.ShowImage(image, 0, 0) - - importedpbststring = scananimatedqr() - - if importedpbststring == "abort": - localrunstate[0] = 0 - localrunstate[1] = "" - return localrunstate - - #parsing transaction info notification screen - draw.rectangle((0, 0, width, height), outline=0, fill=0) - textwidth, textheight = draw.textsize("Parsing txn data...", font=impact22) - draw.text(((240 - textwidth) / 2, 100), "Parsing txn data...", fill="ORANGE", font=impact22) - disp.ShowImage(image, 0, 0) - - print("The selected PSBT is:") - print(importedpbststring) - print("") - - # draw.rectangle((0, 0, width, height), outline=0, fill=0) - # disp.ShowImage(image, 0, 0) - - signedpsbtstring = signtransaction(runstate[1], importedpbststring) - - if signedpsbtstring == "abort": - localrunstate[0] = 0 - localrunstate[1] = "" - return localrunstate - - showqrcodes(signedpsbtstring) - - localrunstate[0] = 0 - localrunstate[1] = "" - - print("You reached the end of the sign_psbt function.") - - return localrunstate \ No newline at end of file diff --git a/views/io_test_view.py b/views/io_test_view.py new file mode 100644 index 00000000..887792d1 --- /dev/null +++ b/views/io_test_view.py @@ -0,0 +1,141 @@ +# External Dependencies +import threading +from threading import Timer + +# Internal file class dependencies +from view import View +from buttons import B +from camera_process import CameraPoll + +class IOTestView(View): + + def __init__(self, controller) -> None: + View.__init__(self, controller) + self.camera_loop_timer = None + self.redraw = False + self.redraw_complete = False + self.qr_text = "Scan ANY QR Code" + + def display_io_test_screen(self): + + # display loading screen + self.draw_modal(["Initializing I/O Test"]) + print("Initializing I/O Test") + self.qr_text = "Scan ANY QR Code" + + # initialize camera + self.controller.to_camera_queue.put(["start"]) + + # First get blocking, this way it's clear when the camera is ready for the end user + self.controller.from_camera_queue.get() + + self.camera_loop_timer = CameraPoll(0.05, self.get_camera_data) # it auto-starts, no need of rt.start() + + while True: + + self.draw_io_screen() + + input = self.buttons.wait_for([B.KEY_UP, B.KEY_DOWN, B.KEY_PRESS, B.KEY_RIGHT, B.KEY_LEFT, B.KEY1, B.KEY2, B.KEY3], False) + if input == B.KEY_UP: + ret_val = self.up_button() + elif input == B.KEY_DOWN: + ret_val = self.down_button() + elif input == B.KEY_RIGHT: + ret_val = self.right_button() + elif input == B.KEY_LEFT: + ret_val = self.left_button() + elif input == B.KEY_PRESS: + ret_val = self.press_button() + elif input == B.KEY1: + ret_val = self.a_button() + elif input == B.KEY2: + ret_val = self.b_button() + elif input == B.KEY3: + ret_val = self.c_button() + return True + + def get_camera_data(self): + try: + data = self.controller.from_camera_queue.get(False) + if data[0] != "nodata": + self.draw_scan_detected() + except: + data = ["nodata"] + + if self.redraw == True and self.redraw_complete == True: + self.draw_io_screen() + + def draw_io_screen(self): + self.redraw_complete = False + self.redraw = False + self.draw.rectangle((0,0,View.canvas_width, View.canvas_height), outline=0, fill=0) + self.draw.text((45, 5), "Input/Output Check:", fill="ORANGE", font=View.IMPACT18) + self.draw.polygon([(61, 89), (80, 46), (99, 89)], outline="ORANGE", fill=0) + self.draw.polygon([(51, 100), (8, 119), (51, 138)], outline="ORANGE", fill=0) + self.draw.polygon([(109, 100), (152, 119), (109, 138)], outline="ORANGE", fill=0) + self.draw.polygon([(61, 151), (80, 193), (99, 151)], outline="ORANGE", fill=0) + self.draw.ellipse([(61, 99), (99, 141)], outline="ORANGE", fill=0) + self.draw.ellipse([(198, 40), (238, 80)], outline="ORANGE", fill=0) + self.draw.ellipse([(198, 95), (238, 135)], outline="ORANGE", fill=0) + self.draw.text((200, 160), "EXIT", fill="ORANGE", font=View.IMPACT18) + self.draw.rectangle((30, 205, 210, 235), outline="ORANGE", fill="BLACK") + tw, th = self.draw.textsize(self.qr_text, font=View.IMPACT22) + self.draw.text(((240 - tw) / 2, 205), self.qr_text, fill="ORANGE", font=View.IMPACT22) + View.DispShowImage() + self.redraw_complete = True + + def a_button(self): + if self.redraw == False and self.redraw_complete == True: + self.draw.ellipse([(198, 40), (238, 80)], outline="ORANGE", fill="ORANGE") + View.DispShowImage() + self.redraw = True + + def b_button(self): + if self.redraw == False and self.redraw_complete == True: + self.draw.ellipse([(198, 95), (238, 135)], outline="ORANGE", fill="ORANGE") + View.DispShowImage() + self.redraw = True + + def c_button(self): + self.camera_loop_timer.stop() + self.controller.to_camera_queue.put(["stop"]) + + def up_button(self): + if self.redraw == False and self.redraw_complete == True: + self.draw.polygon([(61, 89), (80, 46), (99, 89)], outline="ORANGE", fill="ORANGE") + View.DispShowImage() + self.redraw = True + + def down_button(self): + if self.redraw == False and self.redraw_complete == True: + self.draw.polygon([(61, 151), (80, 193), (99, 151)], outline="ORANGE", fill="ORANGE") + View.DispShowImage() + self.redraw = True + + def left_button(self): + if self.redraw == False and self.redraw_complete == True: + self.draw.polygon([(51, 100), (8, 119), (51, 138)], outline="ORANGE", fill="ORANGE") + View.DispShowImage() + self.redraw = True + + def right_button(self): + if self.redraw == False and self.redraw_complete == True: + self.draw.polygon([(109, 100), (152, 119), (109, 138)], outline="ORANGE", fill="ORANGE") + View.DispShowImage() + self.redraw = True + + def press_button(self): + if self.redraw == False and self.redraw_complete == True: + self.draw.ellipse([(61, 99), (99, 141)], outline="ORANGE", fill="ORANGE") + View.DispShowImage() + self.redraw = True + + def draw_scan_detected(self): + self.qr_text = "QR Scanned" + if self.redraw == False and self.redraw_complete == True: + self.draw.rectangle((30, 205, 210, 235), outline="ORANGE", fill="ORANGE") + tw, th = self.draw.textsize(self.qr_text, font=View.IMPACT22) + self.draw.text(((240 - tw) / 2, 205), self.qr_text, fill="BLACK", font=View.IMPACT22) + View.DispShowImage() + self.redraw = True + \ No newline at end of file diff --git a/views/menu_view.py b/views/menu_view.py new file mode 100644 index 00000000..78b6375c --- /dev/null +++ b/views/menu_view.py @@ -0,0 +1,318 @@ +# Internal file class dependencies +from view import View +from buttons import B +from path import Path +from seed_storage import SeedStorage + +# External Dependencies +import time +import re + +class MenuView(View): + + def __init__(self, controller) -> None: + View.__init__(self, controller) + + self.menu_lines = [] + self.selected_menu_num = 1 + + ### + ### Main Navigation + ### + + ### Main Menu + + def display_main_menu(self, sub_menu = None) -> int: + ret_val = 0 + input = 0 + lines = ["Seed Tools", "Signing Tools", "Settings", "Power OFF Device"] + + if sub_menu == Path.SEED_TOOLS_SUB_MENU: + return self.display_seed_tools_menu() + elif sub_menu == Path.SIGNING_TOOLS_SUB_MENU: + return self.display_signing_tools_menu() + elif sub_menu == Path.SETTINGS_SUB_MENU: + return self.display_settings_menu() + else: + self.draw_menu(lines, 1) + + # Wait for Button Input (specifically menu selection/press) + while True: + if ret_val == 0: + input = self.buttons.wait_for([B.KEY_UP, B.KEY_DOWN, B.KEY_PRESS]) + else: + return ret_val + if input == B.KEY_UP: + self.menu_up() + elif input == B.KEY_DOWN: + self.menu_down() + elif input == B.KEY_PRESS: + if self.selected_menu_num == 1: + ret_val = self.display_seed_tools_menu() + elif self.selected_menu_num == 2: + ret_val = self.display_signing_tools_menu() + elif self.selected_menu_num == 3: + ret_val = self.display_settings_menu() + elif self.selected_menu_num == 4: + ret_val = Path.POWER_OFF + + if ret_val != Path.MAIN_MENU: # When no main menu, return to controller + return ret_val + else: + self.draw_menu(lines) + + ### Seed Tools Menu + + def display_seed_tools_menu(self) -> int: + lines = ["... [ Return to Main ]", "Generate Word 12 / 24", "Create a Seed w/ Dice", "Store a Seed (temp)"] + self.draw_menu(lines, 1) + input = 0 + + # Wait for Button Input (specifically menu selection/press) + while True: + input = self.buttons.wait_for([B.KEY_UP, B.KEY_DOWN, B.KEY_PRESS]) + if input == B.KEY_UP: + self.menu_up() + elif input == B.KEY_DOWN: + self.menu_down() + elif input == B.KEY_PRESS: + if self.selected_menu_num == 1: + return Path.MAIN_MENU + elif self.selected_menu_num == 2: + return Path.GEN_LAST_WORD + elif self.selected_menu_num == 3: + return Path.DICE_GEN_SEED + elif self.selected_menu_num == 4: + return Path.SAVE_SEED + + ### Signing Tools Menu + + def display_signing_tools_menu(self) -> None: + lines = ["... [ Return to Main ]", "Generate XPUB", "Sign a Transaction"] + self.draw_menu(lines, 1) + input = 0 + + # Wait for Button Input (specifically menu selection/press) + while True: + input = self.buttons.wait_for([B.KEY_UP, B.KEY_DOWN, B.KEY_PRESS]) + if input == B.KEY_UP: + self.menu_up() + elif input == B.KEY_DOWN: + self.menu_down() + elif input == B.KEY_PRESS: + if self.selected_menu_num == 1: + return Path.MAIN_MENU + elif self.selected_menu_num == 2: + return Path.GEN_XPUB + elif self.selected_menu_num == 3: + return Path.SIGN_TRANSACTION + + ### Settings Menu + + def display_settings_menu(self) -> int: + lines = ["... [ Return to Main ]", "Input / Output Tests", "Current Network: ", "Wallet: ", "Version Info", "Donate to SeedSigner"] + input = 0 + + lines[2] = lines[2].replace("", self.controller.storage.get_network()) + lines[3] = lines[3].replace("", "Specter Desktop") + + # Draw Menu + self.draw_menu(lines, 1) + + # Wait for Button Input (specifically menu selection/press) + while True: + input = self.buttons.wait_for([B.KEY_UP, B.KEY_DOWN, B.KEY_PRESS]) + if input == B.KEY_UP: + self.menu_up() + elif input == B.KEY_DOWN: + self.menu_down() + elif input == B.KEY_PRESS: + if self.selected_menu_num == 1: + return Path.MAIN_MENU + elif self.selected_menu_num == 2: + return Path.IO_TEST_TOOL + elif self.selected_menu_num == 3: + return Path.CURRENT_NETWORK + elif self.selected_menu_num == 4: + return Path.WALLET + elif self.selected_menu_num == 5: + return Path.VERSION_INFO + elif self.selected_menu_num == 6: + return Path.DONATE + + ### Generic Single Menu Selection (returns 1,2,3,4,5,6 ...) + + def display_generic_selection_menu(self, lines = [], title = None, bottom = None) -> int: + self.draw_menu(lines, 1, title, bottom) + + while True: + input = self.buttons.wait_for([B.KEY_UP, B.KEY_DOWN, B.KEY_PRESS]) + if input == B.KEY_UP: + self.menu_up(title, bottom) + elif input == B.KEY_DOWN: + self.menu_down(title, bottom) + elif input == B.KEY_PRESS: + return self.selected_menu_num + + ### Generic Word 12 or 24 seed phrase menu + + def display_12_24_word_menu(self, return_txt = "... [ Return to ... ]") -> int: + lines = [return_txt, "Use a 12 word seed", "Use a 24 word seed"] + self.draw_menu(lines) + + # Wait for Button Input (specifically menu selection/press) + while True: + input = self.buttons.wait_for([B.KEY_UP, B.KEY_DOWN, B.KEY_PRESS]) + if input == B.KEY_UP: + self.menu_up() + elif input == B.KEY_DOWN: + self.menu_down() + elif input == B.KEY_PRESS: + if self.selected_menu_num == 1: + return -1 + elif self.selected_menu_num == 2: + return Path.SEED_WORD_12 + elif self.selected_menu_num == 3: + return Path.SEED_WORD_24 + + ### Select a Seed Slot to Save a Seed Menu + + def display_saved_seed_menu(self, storage, type = 1, return_sel_txt = "... [ Return to Seed Tools ]") -> int: + lines = [] + if return_sel_txt != None: + lines.append(return_sel_txt) + + if type == 1: + # Show all slots used and free + lines.extend(["Use Seed Slot #1", "Use Seed Slot #2", "Use Seed Slot #3"]) + if storage.check_slot_1(): + lines[1] = "Display Seed Slot #1" # replace + if storage.check_slot_2(): + lines[2] = "Display Seed Slot #2" # replace + if storage.check_slot_3(): + lines[3] = "Display Seed Slot #3" # replace + elif type == 2: + # Show only free slots + if storage.check_slot_1() == False: + lines.append("Use Seed Slot #1") + if storage.check_slot_2() == False: + lines.append("Use Seed Slot #2") + if storage.check_slot_3() == False: + lines.append("Use Seed Slot #3") + if storage.num_of_free_slots() == 0: + return 0 + elif type == 3: + # Show only used slots + if storage.check_slot_1(): + lines.append("Use Seed Slot #1") + if storage.check_slot_2(): + lines.append("Use Seed Slot #2") + if storage.check_slot_3(): + lines.append("Use Seed Slot #3") + else: + return 0 + + self.draw_menu(lines) + + # Wait for Button Input (specifically menu selection/press) + while True: + input = self.buttons.wait_for([B.KEY_UP, B.KEY_DOWN, B.KEY_PRESS]) + if input == B.KEY_UP: + self.menu_up() + elif input == B.KEY_DOWN: + self.menu_down() + elif input == B.KEY_PRESS: + if lines[self.selected_menu_num-1] == return_sel_txt: + return 0 + else: + return int(re.search("#(\d+)", lines[self.selected_menu_num-1], re.IGNORECASE).group(1)) + + ### + ### Generic Reusable Menu Methods/Functions + ### + + ### Generic Draw Menu Method + + def draw_menu(self, lines, selected_menu_num = 1, title = None, bottom = None) -> None: + if title == None: + t = "SeedSigner v" + self.controller.VERSION + else: + t = title + + if bottom == None: + b = "Press Control Stick to Select" + else: + b = bottom + + if lines != self.menu_lines or selected_menu_num != self.selected_menu_num: + #Menu has changed, redraw + + View.draw.rectangle((0, 0, View.canvas_width, View.canvas_height), outline=0, fill=0) + tw, th = View.draw.textsize(t, font=View.IMPACT22) + View.draw.text(((240 - tw) / 2, 2), t, fill="ORANGE", font=View.IMPACT22) + + num_of_lines = len(lines) + + if selected_menu_num <= 4: + if num_of_lines >= 1: + self.draw_menu_text(15, 45 , lines[0], (True if selected_menu_num == 1 else False)) + if num_of_lines >= 2: + self.draw_menu_text(15, 80 , lines[1], (True if selected_menu_num == 2 else False)) + if num_of_lines >= 3: + self.draw_menu_text(15, 115, lines[2], (True if selected_menu_num == 3 else False)) + if num_of_lines >= 4: + self.draw_menu_text(15, 150, lines[3], (True if selected_menu_num == 4 else False)) + elif selected_menu_num >= 5 and selected_menu_num <= 8: + if num_of_lines >= 5: + self.draw_menu_text(15, 45 , lines[4], (True if selected_menu_num == 5 else False)) + if num_of_lines >= 6: + self.draw_menu_text(15, 80 , lines[5], (True if selected_menu_num == 6 else False)) + if num_of_lines >= 7: + self.draw_menu_text(15, 115, lines[6], (True if selected_menu_num == 7 else False)) + if num_of_lines >= 8: + self.draw_menu_text(15, 150, lines[7], (True if selected_menu_num == 8 else False)) + elif selected_menu_num >= 9 and selected_menu_num <= 12: + if num_of_lines >= 9: + self.draw_menu_text(15, 45 , lines[8], (True if selected_menu_num == 9 else False)) + if num_of_lines >= 10: + self.draw_menu_text(15, 80 , lines[9], (True if selected_menu_num == 10 else False)) + if num_of_lines >= 11: + self.draw_menu_text(15, 115, lines[10], (True if selected_menu_num == 11 else False)) + if num_of_lines >= 12: + self.draw_menu_text(15, 150, lines[11], (True if selected_menu_num == 12 else False)) + + tw, th = View.draw.textsize(b, font=View.IMPACT18) + View.draw.text(((240 - tw) / 2, 210), b, fill="ORANGE", font=View.IMPACT18) + View.DispShowImage() + + # saved update menu lines and selection + self.menu_lines = lines + self.selected_menu_num = selected_menu_num + + return + + ### Generic Menu Navigation + + def menu_up(self, title = None, bottom = None): + if self.selected_menu_num <= 1: + self.draw_menu(self.menu_lines, len(self.menu_lines), title, bottom) + else: + self.draw_menu(self.menu_lines, self.selected_menu_num - 1, title, bottom) + + def menu_down(self, title = None, bottom = None): + if self.selected_menu_num >= len(self.menu_lines): + self.draw_menu(self.menu_lines, 1, title, bottom) + else: + self.draw_menu(self.menu_lines, self.selected_menu_num + 1, title, bottom) + + ### Internal View Method to Display a Line in a Menu Screen + + def draw_menu_text(self, x, y, line, selected) -> None: + + if selected == True: + View.draw.rectangle((5, y-5, 235, y+30), outline=0, fill="ORANGE") + View.draw.text((x, y) , line, fill="BLACK", font=View.IMPACT20) + else: + View.draw.text((x, y) , line, fill="ORANGE", font=View.IMPACT20) + + return diff --git a/views/seed_tools_view.py b/views/seed_tools_view.py new file mode 100644 index 00000000..e41dac3c --- /dev/null +++ b/views/seed_tools_view.py @@ -0,0 +1,575 @@ +# External Dependencies +from embit.bip39 import mnemonic_to_bytes +from embit.bip39 import mnemonic_from_bytes +from embit import bip39 +import time + +# Internal file class dependencies +from view import View +from buttons import B + +class SeedToolsView(View): + + SEEDWORDS = ["abandon", "ability", "able", "about", "above", "absent", "absorb", "abstract", "absurd", "abuse", "access", "accident", "account", "accuse", "achieve", "acid", "acoustic", "acquire", "across", "act", "action", "actor", "actress", "actual", "adapt", "add", "addict", "address", "adjust", "admit", "adult", "advance", "advice", "aerobic", "affair", "afford", "afraid", "again", "age", "agent", "agree", "ahead", "aim", "air", "airport", "aisle", "alarm", "album", "alcohol", "alert", "alien", "all", "alley", "allow", "almost", "alone", "alpha", "already", "also", "alter", "always", "amateur", "amazing", "among", "amount", "amused", "analyst", "anchor", "ancient", "anger", "angle", "angry", "animal", "ankle", "announce", "annual", "another", "answer", "antenna", "antique", "anxiety", "any", "apart", "apology", "appear", "apple", "approve", "april", "arch", "arctic", "area", "arena", "argue", "arm", "armed", "armor", "army", "around", "arrange", "arrest", "arrive", "arrow", "art", "artefact", "artist", "artwork", "ask", "aspect", "assault", "asset", "assist", "assume", "asthma", "athlete", "atom", "attack", "attend", "attitude", "attract", "auction", "audit", "august", "aunt", "author", "auto", "autumn", "average", "avocado", "avoid", "awake", "aware", "away", "awesome", "awful", "awkward", "axis", "baby", "bachelor", "bacon", "badge", "bag", "balance", "balcony", "ball", "bamboo", "banana", "banner", "bar", "barely", "bargain", "barrel", "base", "basic", "basket", "battle", "beach", "bean", "beauty", "because", "become", "beef", "before", "begin", "behave", "behind", "believe", "below", "belt", "bench", "benefit", "best", "betray", "better", "between", "beyond", "bicycle", "bid", "bike", "bind", "biology", "bird", "birth", "bitter", "black", "blade", "blame", "blanket", "blast", "bleak", "bless", "blind", "blood", "blossom", "blouse", "blue", "blur", "blush", "board", "boat", "body", "boil", "bomb", "bone", "bonus", "book", "boost", "border", "boring", "borrow", "boss", "bottom", "bounce", "box", "boy", "bracket", "brain", "brand", "brass", "brave", "bread", "breeze", "brick", "bridge", "brief", "bright", "bring", "brisk", "broccoli", "broken", "bronze", "broom", "brother", "brown", "brush", "bubble", "buddy", "budget", "buffalo", "build", "bulb", "bulk", "bullet", "bundle", "bunker", "burden", "burger", "burst", "bus", "business", "busy", "butter", "buyer", "buzz", "cabbage", "cabin", "cable", "cactus", "cage", "cake", "call", "calm", "camera", "camp", "can", "canal", "cancel", "candy", "cannon", "canoe", "canvas", "canyon", "capable", "capital", "captain", "car", "carbon", "card", "cargo", "carpet", "carry", "cart", "case", "cash", "casino", "castle", "casual", "cat", "catalog", "catch", "category", "cattle", "caught", "cause", "caution", "cave", "ceiling", "celery", "cement", "census", "century", "cereal", "certain", "chair", "chalk", "champion", "change", "chaos", "chapter", "charge", "chase", "chat", "cheap", "check", "cheese", "chef", "cherry", "chest", "chicken", "chief", "child", "chimney", "choice", "choose", "chronic", "chuckle", "chunk", "churn", "cigar", "cinnamon", "circle", "citizen", "city", "civil", "claim", "clap", "clarify", "claw", "clay", "clean", "clerk", "clever", "click", "client", "cliff", "climb", "clinic", "clip", "clock", "clog", "close", "cloth", "cloud", "clown", "club", "clump", "cluster", "clutch", "coach", "coast", "coconut", "code", "coffee", "coil", "coin", "collect", "color", "column", "combine", "come", "comfort", "comic", "common", "company", "concert", "conduct", "confirm", "congress", "connect", "consider", "control", "convince", "cook", "cool", "copper", "copy", "coral", "core", "corn", "correct", "cost", "cotton", "couch", "country", "couple", "course", "cousin", "cover", "coyote", "crack", "cradle", "craft", "cram", "crane", "crash", "crater", "crawl", "crazy", "cream", "credit", "creek", "crew", "cricket", "crime", "crisp", "critic", "crop", "cross", "crouch", "crowd", "crucial", "cruel", "cruise", "crumble", "crunch", "crush", "cry", "crystal", "cube", "culture", "cup", "cupboard", "curious", "current", "curtain", "curve", "cushion", "custom", "cute", "cycle", "dad", "damage", "damp", "dance", "danger", "daring", "dash", "daughter", "dawn", "day", "deal", "debate", "debris", "decade", "december", "decide", "decline", "decorate", "decrease", "deer", "defense", "define", "defy", "degree", "delay", "deliver", "demand", "demise", "denial", "dentist", "deny", "depart", "depend", "deposit", "depth", "deputy", "derive", "describe", "desert", "design", "desk", "despair", "destroy", "detail", "detect", "develop", "device", "devote", "diagram", "dial", "diamond", "diary", "dice", "diesel", "diet", "differ", "digital", "dignity", "dilemma", "dinner", "dinosaur", "direct", "dirt", "disagree", "discover", "disease", "dish", "dismiss", "disorder", "display", "distance", "divert", "divide", "divorce", "dizzy", "doctor", "document", "dog", "doll", "dolphin", "domain", "donate", "donkey", "donor", "door", "dose", "double", "dove", "draft", "dragon", "drama", "drastic", "draw", "dream", "dress", "drift", "drill", "drink", "drip", "drive", "drop", "drum", "dry", "duck", "dumb", "dune", "during", "dust", "dutch", "duty", "dwarf", "dynamic", "eager", "eagle", "early", "earn", "earth", "easily", "east", "easy", "echo", "ecology", "economy", "edge", "edit", "educate", "effort", "egg", "eight", "either", "elbow", "elder", "electric", "elegant", "element", "elephant", "elevator", "elite", "else", "embark", "embody", "embrace", "emerge", "emotion", "employ", "empower", "empty", "enable", "enact", "end", "endless", "endorse", "enemy", "energy", "enforce", "engage", "engine", "enhance", "enjoy", "enlist", "enough", "enrich", "enroll", "ensure", "enter", "entire", "entry", "envelope", "episode", "equal", "equip", "era", "erase", "erode", "erosion", "error", "erupt", "escape", "essay", "essence", "estate", "eternal", "ethics", "evidence", "evil", "evoke", "evolve", "exact", "example", "excess", "exchange", "excite", "exclude", "excuse", "execute", "exercise", "exhaust", "exhibit", "exile", "exist", "exit", "exotic", "expand", "expect", "expire", "explain", "expose", "express", "extend", "extra", "eye", "eyebrow", "fabric", "face", "faculty", "fade", "faint", "faith", "fall", "false", "fame", "family", "famous", "fan", "fancy", "fantasy", "farm", "fashion", "fat", "fatal", "father", "fatigue", "fault", "favorite", "feature", "february", "federal", "fee", "feed", "feel", "female", "fence", "festival", "fetch", "fever", "few", "fiber", "fiction", "field", "figure", "file", "film", "filter", "final", "find", "fine", "finger", "finish", "fire", "firm", "first", "fiscal", "fish", "fit", "fitness", "fix", "flag", "flame", "flash", "flat", "flavor", "flee", "flight", "flip", "float", "flock", "floor", "flower", "fluid", "flush", "fly", "foam", "focus", "fog", "foil", "fold", "follow", "food", "foot", "force", "forest", "forget", "fork", "fortune", "forum", "forward", "fossil", "foster", "found", "fox", "fragile", "frame", "frequent", "fresh", "friend", "fringe", "frog", "front", "frost", "frown", "frozen", "fruit", "fuel", "fun", "funny", "furnace", "fury", "future", "gadget", "gain", "galaxy", "gallery", "game", "gap", "garage", "garbage", "garden", "garlic", "garment", "gas", "gasp", "gate", "gather", "gauge", "gaze", "general", "genius", "genre", "gentle", "genuine", "gesture", "ghost", "giant", "gift", "giggle", "ginger", "giraffe", "girl", "give", "glad", "glance", "glare", "glass", "glide", "glimpse", "globe", "gloom", "glory", "glove", "glow", "glue", "goat", "goddess", "gold", "good", "goose", "gorilla", "gospel", "gossip", "govern", "gown", "grab", "grace", "grain", "grant", "grape", "grass", "gravity", "great", "green", "grid", "grief", "grit", "grocery", "group", "grow", "grunt", "guard", "guess", "guide", "guilt", "guitar", "gun", "gym", "habit", "hair", "half", "hammer", "hamster", "hand", "happy", "harbor", "hard", "harsh", "harvest", "hat", "have", "hawk", "hazard", "head", "health", "heart", "heavy", "hedgehog", "height", "hello", "helmet", "help", "hen", "hero", "hidden", "high", "hill", "hint", "hip", "hire", "history", "hobby", "hockey", "hold", "hole", "holiday", "hollow", "home", "honey", "hood", "hope", "horn", "horror", "horse", "hospital", "host", "hotel", "hour", "hover", "hub", "huge", "human", "humble", "humor", "hundred", "hungry", "hunt", "hurdle", "hurry", "hurt", "husband", "hybrid", "ice", "icon", "idea", "identify", "idle", "ignore", "ill", "illegal", "illness", "image", "imitate", "immense", "immune", "impact", "impose", "improve", "impulse", "inch", "include", "income", "increase", "index", "indicate", "indoor", "industry", "infant", "inflict", "inform", "inhale", "inherit", "initial", "inject", "injury", "inmate", "inner", "innocent", "input", "inquiry", "insane", "insect", "inside", "inspire", "install", "intact", "interest", "into", "invest", "invite", "involve", "iron", "island", "isolate", "issue", "item", "ivory", "jacket", "jaguar", "jar", "jazz", "jealous", "jeans", "jelly", "jewel", "job", "join", "joke", "journey", "joy", "judge", "juice", "jump", "jungle", "junior", "junk", "just", "kangaroo", "keen", "keep", "ketchup", "key", "kick", "kid", "kidney", "kind", "kingdom", "kiss", "kit", "kitchen", "kite", "kitten", "kiwi", "knee", "knife", "knock", "know", "lab", "label", "labor", "ladder", "lady", "lake", "lamp", "language", "laptop", "large", "later", "latin", "laugh", "laundry", "lava", "law", "lawn", "lawsuit", "layer", "lazy", "leader", "leaf", "learn", "leave", "lecture", "left", "leg", "legal", "legend", "leisure", "lemon", "lend", "length", "lens", "leopard", "lesson", "letter", "level", "liar", "liberty", "library", "license", "life", "lift", "light", "like", "limb", "limit", "link", "lion", "liquid", "list", "little", "live", "lizard", "load", "loan", "lobster", "local", "lock", "logic", "lonely", "long", "loop", "lottery", "loud", "lounge", "love", "loyal", "lucky", "luggage", "lumber", "lunar", "lunch", "luxury", "lyrics", "machine", "mad", "magic", "magnet", "maid", "mail", "main", "major", "make", "mammal", "man", "manage", "mandate", "mango", "mansion", "manual", "maple", "marble", "march", "margin", "marine", "market", "marriage", "mask", "mass", "master", "match", "material", "math", "matrix", "matter", "maximum", "maze", "meadow", "mean", "measure", "meat", "mechanic", "medal", "media", "melody", "melt", "member", "memory", "mention", "menu", "mercy", "merge", "merit", "merry", "mesh", "message", "metal", "method", "middle", "midnight", "milk", "million", "mimic", "mind", "minimum", "minor", "minute", "miracle", "mirror", "misery", "miss", "mistake", "mix", "mixed", "mixture", "mobile", "model", "modify", "mom", "moment", "monitor", "monkey", "monster", "month", "moon", "moral", "more", "morning", "mosquito", "mother", "motion", "motor", "mountain", "mouse", "move", "movie", "much", "muffin", "mule", "multiply", "muscle", "museum", "mushroom", "music", "must", "mutual", "myself", "mystery", "myth", "naive", "name", "napkin", "narrow", "nasty", "nation", "nature", "near", "neck", "need", "negative", "neglect", "neither", "nephew", "nerve", "nest", "net", "network", "neutral", "never", "news", "next", "nice", "night", "noble", "noise", "nominee", "noodle", "normal", "north", "nose", "notable", "note", "nothing", "notice", "novel", "now", "nuclear", "number", "nurse", "nut", "oak", "obey", "object", "oblige", "obscure", "observe", "obtain", "obvious", "occur", "ocean", "october", "odor", "off", "offer", "office", "often", "oil", "okay", "old", "olive", "olympic", "omit", "once", "one", "onion", "online", "only", "open", "opera", "opinion", "oppose", "option", "orange", "orbit", "orchard", "order", "ordinary", "organ", "orient", "original", "orphan", "ostrich", "other", "outdoor", "outer", "output", "outside", "oval", "oven", "over", "own", "owner", "oxygen", "oyster", "ozone", "pact", "paddle", "page", "pair", "palace", "palm", "panda", "panel", "panic", "panther", "paper", "parade", "parent", "park", "parrot", "party", "pass", "patch", "path", "patient", "patrol", "pattern", "pause", "pave", "payment", "peace", "peanut", "pear", "peasant", "pelican", "pen", "penalty", "pencil", "people", "pepper", "perfect", "permit", "person", "pet", "phone", "photo", "phrase", "physical", "piano", "picnic", "picture", "piece", "pig", "pigeon", "pill", "pilot", "pink", "pioneer", "pipe", "pistol", "pitch", "pizza", "place", "planet", "plastic", "plate", "play", "please", "pledge", "pluck", "plug", "plunge", "poem", "poet", "point", "polar", "pole", "police", "pond", "pony", "pool", "popular", "portion", "position", "possible", "post", "potato", "pottery", "poverty", "powder", "power", "practice", "praise", "predict", "prefer", "prepare", "present", "pretty", "prevent", "price", "pride", "primary", "print", "priority", "prison", "private", "prize", "problem", "process", "produce", "profit", "program", "project", "promote", "proof", "property", "prosper", "protect", "proud", "provide", "public", "pudding", "pull", "pulp", "pulse", "pumpkin", "punch", "pupil", "puppy", "purchase", "purity", "purpose", "purse", "push", "put", "puzzle", "pyramid", "quality", "quantum", "quarter", "question", "quick", "quit", "quiz", "quote", "rabbit", "raccoon", "race", "rack", "radar", "radio", "rail", "rain", "raise", "rally", "ramp", "ranch", "random", "range", "rapid", "rare", "rate", "rather", "raven", "raw", "razor", "ready", "real", "reason", "rebel", "rebuild", "recall", "receive", "recipe", "record", "recycle", "reduce", "reflect", "reform", "refuse", "region", "regret", "regular", "reject", "relax", "release", "relief", "rely", "remain", "remember", "remind", "remove", "render", "renew", "rent", "reopen", "repair", "repeat", "replace", "report", "require", "rescue", "resemble", "resist", "resource", "response", "result", "retire", "retreat", "return", "reunion", "reveal", "review", "reward", "rhythm", "rib", "ribbon", "rice", "rich", "ride", "ridge", "rifle", "right", "rigid", "ring", "riot", "ripple", "risk", "ritual", "rival", "river", "road", "roast", "robot", "robust", "rocket", "romance", "roof", "rookie", "room", "rose", "rotate", "rough", "round", "route", "royal", "rubber", "rude", "rug", "rule", "run", "runway", "rural", "sad", "saddle", "sadness", "safe", "sail", "salad", "salmon", "salon", "salt", "salute", "same", "sample", "sand", "satisfy", "satoshi", "sauce", "sausage", "save", "say", "scale", "scan", "scare", "scatter", "scene", "scheme", "school", "science", "scissors", "scorpion", "scout", "scrap", "screen", "script", "scrub", "sea", "search", "season", "seat", "second", "secret", "section", "security", "seed", "seek", "segment", "select", "sell", "seminar", "senior", "sense", "sentence", "series", "service", "session", "settle", "setup", "seven", "shadow", "shaft", "shallow", "share", "shed", "shell", "sheriff", "shield", "shift", "shine", "ship", "shiver", "shock", "shoe", "shoot", "shop", "short", "shoulder", "shove", "shrimp", "shrug", "shuffle", "shy", "sibling", "sick", "side", "siege", "sight", "sign", "silent", "silk", "silly", "silver", "similar", "simple", "since", "sing", "siren", "sister", "situate", "six", "size", "skate", "sketch", "ski", "skill", "skin", "skirt", "skull", "slab", "slam", "sleep", "slender", "slice", "slide", "slight", "slim", "slogan", "slot", "slow", "slush", "small", "smart", "smile", "smoke", "smooth", "snack", "snake", "snap", "sniff", "snow", "soap", "soccer", "social", "sock", "soda", "soft", "solar", "soldier", "solid", "solution", "solve", "someone", "song", "soon", "sorry", "sort", "soul", "sound", "soup", "source", "south", "space", "spare", "spatial", "spawn", "speak", "special", "speed", "spell", "spend", "sphere", "spice", "spider", "spike", "spin", "spirit", "split", "spoil", "sponsor", "spoon", "sport", "spot", "spray", "spread", "spring", "spy", "square", "squeeze", "squirrel", "stable", "stadium", "staff", "stage", "stairs", "stamp", "stand", "start", "state", "stay", "steak", "steel", "stem", "step", "stereo", "stick", "still", "sting", "stock", "stomach", "stone", "stool", "story", "stove", "strategy", "street", "strike", "strong", "struggle", "student", "stuff", "stumble", "style", "subject", "submit", "subway", "success", "such", "sudden", "suffer", "sugar", "suggest", "suit", "summer", "sun", "sunny", "sunset", "super", "supply", "supreme", "sure", "surface", "surge", "surprise", "surround", "survey", "suspect", "sustain", "swallow", "swamp", "swap", "swarm", "swear", "sweet", "swift", "swim", "swing", "switch", "sword", "symbol", "symptom", "syrup", "system", "table", "tackle", "tag", "tail", "talent", "talk", "tank", "tape", "target", "task", "taste", "tattoo", "taxi", "teach", "team", "tell", "ten", "tenant", "tennis", "tent", "term", "test", "text", "thank", "that", "theme", "then", "theory", "there", "they", "thing", "this", "thought", "three", "thrive", "throw", "thumb", "thunder", "ticket", "tide", "tiger", "tilt", "timber", "time", "tiny", "tip", "tired", "tissue", "title", "toast", "tobacco", "today", "toddler", "toe", "together", "toilet", "token", "tomato", "tomorrow", "tone", "tongue", "tonight", "tool", "tooth", "top", "topic", "topple", "torch", "tornado", "tortoise", "toss", "total", "tourist", "toward", "tower", "town", "toy", "track", "trade", "traffic", "tragic", "train", "transfer", "trap", "trash", "travel", "tray", "treat", "tree", "trend", "trial", "tribe", "trick", "trigger", "trim", "trip", "trophy", "trouble", "truck", "true", "truly", "trumpet", "trust", "truth", "try", "tube", "tuition", "tumble", "tuna", "tunnel", "turkey", "turn", "turtle", "twelve", "twenty", "twice", "twin", "twist", "two", "type", "typical", "ugly", "umbrella", "unable", "unaware", "uncle", "uncover", "under", "undo", "unfair", "unfold", "unhappy", "uniform", "unique", "unit", "universe", "unknown", "unlock", "until", "unusual", "unveil", "update", "upgrade", "uphold", "upon", "upper", "upset", "urban", "urge", "usage", "use", "used", "useful", "useless", "usual", "utility", "vacant", "vacuum", "vague", "valid", "valley", "valve", "van", "vanish", "vapor", "various", "vast", "vault", "vehicle", "velvet", "vendor", "venture", "venue", "verb", "verify", "version", "very", "vessel", "veteran", "viable", "vibrant", "vicious", "victory", "video", "view", "village", "vintage", "violin", "virtual", "virus", "visa", "visit", "visual", "vital", "vivid", "vocal", "voice", "void", "volcano", "volume", "vote", "voyage", "wage", "wagon", "wait", "walk", "wall", "walnut", "want", "warfare", "warm", "warrior", "wash", "wasp", "waste", "water", "wave", "way", "wealth", "weapon", "wear", "weasel", "weather", "web", "wedding", "weekend", "weird", "welcome", "west", "wet", "whale", "what", "wheat", "wheel", "when", "where", "whip", "whisper", "wide", "width", "wife", "wild", "will", "win", "window", "wine", "wing", "wink", "winner", "winter", "wire", "wisdom", "wise", "wish", "witness", "wolf", "woman", "wonder", "wood", "wool", "word", "work", "world", "worry", "worth", "wrap", "wreck", "wrestle", "wrist", "write", "wrong", "yard", "year", "yellow", "you", "young", "youth", "zebra", "zero", "zone", "zoo"] + + ALPHABET = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"] + + def __init__(self, controller) -> None: + View.__init__(self, controller) + + # Gather words and seed display information + self.words = [] + self.letters = [] + self.possible_alphabet = [] + self.possible_words = [] + self.seed_length = 12 # Default to 12, Valid values are 11, 12, 23 and 24 + + # Dice information + self.roll_number = 1 + self.dice_selected = 0 + self.roll_data = "" + self.dice_seed_phrase = [] + + ### + ### Display Gather Words Screen + ### + + def display_gather_words_screen(self, num_of_words, slot_num = 0) -> []: + self.seed_length = num_of_words + + self.reset() + self.draw_gather_words() + + # Wait for Button Input (specifically menu selection/press) + while True: + input = self.buttons.wait_for([B.KEY_UP, B.KEY_DOWN, B.KEY_PRESS, B.KEY_RIGHT, B.KEY_LEFT, B.KEY1, B.KEY2, B.KEY3]) + if input == B.KEY_UP: + ret_val = self.gather_words_up() + elif input == B.KEY_DOWN: + ret_val = self.gather_words_down() + elif input == B.KEY_RIGHT: + ret_val = self.gather_words_right() + elif input == B.KEY_LEFT: + ret_val = self.gather_words_left() + elif input == B.KEY_PRESS: + ret_val = self.gather_words_press() + elif input == B.KEY1: + ret_val = self.gather_words_a() + elif input == B.KEY2: + ret_val = self.gather_words_b() + elif input == B.KEY3: + ret_val = self.gather_words_c() + + if ret_val == False: + return [] + + if len(self.words) == self.seed_length: + return self.words[:] + + self.draw_gather_words() + + def gather_words_up(self): + View.draw.polygon([(8 + ((len(self.letters)-1)*30), 85) , (14 + ((len(self.letters)-1)*30), 69) , (20 + ((len(self.letters)-1)*30), 85 )], outline="ORANGE", fill="ORANGE") + View.DispShowImage() + + self.calc_possible_alphabet() + if self.letters[len(self.letters)-1] == self.possible_alphabet[0]: + self.letters[len(self.letters)-1] = self.possible_alphabet[-1] + else: + try: + idx = self.possible_alphabet.index(self.letters[len(self.letters)-1]) + self.letters[len(self.letters)-1] = self.possible_alphabet[idx-1] + except (ValueError, IndexError): + print("not found error") + + def gather_words_down(self): + View.draw.polygon([(8 + ((len(self.letters)-1)*30), 148), (14 + ((len(self.letters)-1)*30), 164), (20 + ((len(self.letters)-1)*30), 148)], outline="ORANGE", fill="ORANGE") + View.DispShowImage() + + self.calc_possible_alphabet() + if self.letters[len(self.letters)-1] == self.possible_alphabet[-1]: + self.letters[len(self.letters)-1] = self.possible_alphabet[0] + else: + try: + idx = self.possible_alphabet.index(self.letters[len(self.letters)-1]) + self.letters[len(self.letters)-1] = self.possible_alphabet[idx+1] + except (ValueError, IndexError): + print("not found error") + + def gather_words_right(self): + if len(self.letters) < 4: + self.calc_possible_alphabet(True) + self.letters.append(self.possible_alphabet[0]) + + def gather_words_left(self) -> bool: + if len(self.letters) == 1: + if len(self.words) == 0: + return False + else: + self.words.pop() + else: + self.letters.pop() + return True + + def gather_words_press(self): + self.gather_words_right() + + def gather_words_a(self): + if len(self.possible_words) >= 1: # skip everything if there is no word next to the button + self.letters.clear() + self.words.append(self.possible_words[0]) + if len(self.words) < self.seed_length: + self.possible_alphabet = SeedToolsView.ALPHABET[:] + self.letters.append(self.possible_alphabet[0]) + return + else: + self.letters.append(SeedToolsView.ALPHABET[0]) + else: + return + + def gather_words_b(self): + if len(self.possible_words) >= 2: # skip everything if there is no word next to the button + self.letters.clear() + self.words.append(self.possible_words[1]) + if len(self.words) < self.seed_length: + self.possible_alphabet = SeedToolsView.ALPHABET[:] + self.letters.append(self.possible_alphabet[0]) + return + else: + self.letters.append(SeedToolsView.ALPHABET[0]) + else: + return + + def gather_words_c(self): + if len(self.possible_words) >= 3: # skip everything if there is no word next to the button + self.letters.clear() + self.words.append(self.possible_words[2]) + if len(self.words) < self.seed_length: + self.possible_alphabet = SeedToolsView.ALPHABET[:] + self.letters.append(self.possible_alphabet[0]) + return + else: + self.letters.append(SeedToolsView.ALPHABET[0]) + else: + return + + def draw_gather_words(self): + + View.draw.rectangle((0, 0, View.canvas_width, View.canvas_height), outline=0, fill=0) + View.draw.text((75, 2), "Seed Word: " + str(len(self.words)+1), fill="ORANGE", font=View.IMPACT18) + View.draw.text((15, 210), "(choose from words on right)", fill="ORANGE", font=View.IMPACT18) + + # draw possible words (3 at most) + self.possible_words = [i for i in SeedToolsView.SEEDWORDS if i.startswith("".join(self.letters))] + if len(self.possible_words) >= 1: + for idx, word in enumerate(self.possible_words, start=0): + word_offset = 223 - View.IMPACT25.getsize(word)[0] + View.draw.text((word_offset, 39 + (60*idx)), word + " -", fill="ORANGE", font=View.IMPACT25) + if idx >= 2: + break + + # draw letter and arrows + for idx, letter in enumerate(self.letters, start=0): + tw, th = View.draw.textsize(letter, font=View.IMPACT35) + View.draw.text((((idx*30)+((30-tw)/2)), 92), letter, fill="ORANGE", font=View.IMPACT35) + if idx+1 == len(self.letters): + # draw arrows only above last/active letter + View.draw.polygon([(8 + (idx*30), 85) , (14 + (idx*30), 69) , (20 + (idx*30), 85 )], outline="ORANGE", fill="BLACK") + View.draw.polygon([(8 + (idx*30), 148), (14 + (idx*30), 164), (20 + (idx*30), 148)], outline="ORANGE", fill="BLACK") + + View.DispShowImage() + + return + + ### + ### Display Last Word + ### + + def display_last_word(self, partial_seed_phrase) -> list: + print("display last word") + + stringphrase = " ".join(partial_seed_phrase).strip() + " abandon" + bytes = mnemonic_to_bytes(stringphrase, ignore_checksum=True) + finalseed = mnemonic_from_bytes(bytes) + splitseed = finalseed.split() + last_word = splitseed[-1] + + self.draw.rectangle((0, 0, View.canvas_width, View.canvas_height), outline=0, fill=0) + tw, th = self.draw.textsize("The final word is :", font=View.IMPACT23) + self.draw.text(((240 - tw) / 2, 60), "The final word is :", fill="ORANGE", font=View.IMPACT23) + tw, th = self.draw.textsize(last_word, font=View.IMPACT50) + self.draw.text(((240 - tw) / 2, 90), last_word, fill="ORANGE", font=View.IMPACT50) + self.draw.text((73, 210), "Right to Continue", fill="ORANGE", font=View.IMPACT18) + View.DispShowImage() + + input = self.buttons.wait_for([B.KEY_RIGHT]) + return splitseed[:] + + ### + ### Display Seed from Dice + ### + + def display_generate_seed_from_dice(self): + self.roll_number = 1 + self.dice_selected = 0 + self.roll_data = "" + + self.draw_dice(1) + time.sleep(1) # pause for 1 second before accepting input + + # Wait for Button Input (specifically menu selection/press) + while True: + input = self.buttons.wait_for([B.KEY_UP, B.KEY_DOWN, B.KEY_PRESS, B.KEY_RIGHT, B.KEY_LEFT]) + if input == B.KEY_UP: + ret_val = self.dice_arrow_up() + elif input == B.KEY_DOWN: + ret_val = self.dice_arrow_down() + elif input == B.KEY_RIGHT: + ret_val = self.dice_arrow_right() + elif input == B.KEY_LEFT: + ret_val = self.dice_arrow_left() + elif input == B.KEY_PRESS: + ret_val = self.dice_arrow_press() + + if ret_val == False: + return [] + + if self.roll_number >= 100: + self.dice_seed_phrase = self.calc_seed_from_dice() + return self.dice_seed_phrase[:] + + def dice_arrow_up(self): + new_selection = 0 + if self.dice_selected == 4: + new_selection = 1 + elif self.dice_selected == 5: + new_selection = 2 + elif self.dice_selected == 6: + new_selection = 3 + + if self.dice_selected != new_selection and new_selection != 0: + self.draw_dice(new_selection) + + return True + + def dice_arrow_down(self): + new_selection = 0 + if self.dice_selected == 1: + new_selection = 4 + elif self.dice_selected == 2: + new_selection = 5 + elif self.dice_selected == 3: + new_selection = 6 + + if self.dice_selected != new_selection and new_selection != 0: + self.draw_dice(new_selection) + + return True + + def dice_arrow_right(self): + new_selection = 0 + if self.dice_selected == 1: + new_selection = 2 + elif self.dice_selected == 2: + new_selection = 3 + elif self.dice_selected == 4: + new_selection = 5 + elif self.dice_selected == 5: + new_selection = 6 + + if self.dice_selected != new_selection and new_selection != 0: + self.draw_dice(new_selection) + + return True + + def dice_arrow_left(self): + if self.dice_selected == 1: + self.draw_prompt_custom("Undo ", "Cancel ", "Exit ", ["Action: ", "", ""]) + input = self.buttons.wait_for([B.KEY1, B.KEY2, B.KEY3]) + if input == B.KEY1: #Undo + self.roll_number = self.roll_number - 1 + self.roll_data = self.roll_data[:-1] # remove last character from string + if self.roll_number >= 1: + self.draw_dice(self.dice_selected) + return True + else: + return False + elif input == B.KEY2: # Cancel + self.draw_dice(self.dice_selected) + return True + elif input == B.KEY3: # Exit + return False + + new_selection = 0 + if self.dice_selected == 3: + new_selection = 2 + elif self.dice_selected == 2: + new_selection = 1 + elif self.dice_selected == 6: + new_selection = 5 + elif self.dice_selected == 5: + new_selection = 4 + + if self.dice_selected != new_selection and new_selection != 0: + self.draw_dice(new_selection) + + return True + + def dice_arrow_press(self): + self.roll_number = self.roll_number + 1 + if self.dice_selected == 6: + self.roll_data = self.roll_data + str(0).strip() + else: + self.roll_data = self.roll_data + str(self.dice_selected).strip() + self.dice_selected = 1 + if self.roll_number < 100: + self.draw_dice(self.dice_selected) + + return True + + def draw_dice(self, dice_selected): + + self.draw.rectangle((0, 0, View.canvas_width, View.canvas_height), outline=0, fill=0) + self.draw.text((45, 5), "Dice roll: " + str(self.roll_number) + "/99", fill="ORANGE", font=View.IMPACT26) + + # when dice is selected, rect fill will be orange and ellipse will be black, ellipse outline will be the black + # when dice is not selected, rect will will be black and ellipse will be orange, ellipse outline will be orange + + # dice 1 + if dice_selected == 1: + self.draw.rectangle((5, 50, 75, 120), outline="ORANGE", fill="ORANGE") + self.draw.ellipse([(34, 79), (46, 91)], outline="BLACK", fill="BLACK") + else: + self.draw.rectangle((5, 50, 75, 120), outline="ORANGE", fill="BLACK") + self.draw.ellipse([(34, 79), (46, 91)], outline="ORANGE", fill="ORANGE") + + # dice 2 + if dice_selected == 2: + self.draw.rectangle((85, 50, 155, 120), outline="ORANGE", fill="ORANGE") + self.draw.ellipse([(100, 60), (112, 72)], outline="BLACK", fill="BLACK") + self.draw.ellipse([(128, 98), (140, 110)], outline="BLACK", fill="BLACK") + else: + self.draw.rectangle((85, 50, 155, 120), outline="ORANGE", fill="BLACK") + self.draw.ellipse([(100, 60), (112, 72)], outline="ORANGE", fill="ORANGE") + self.draw.ellipse([(128, 98), (140, 110)], outline="ORANGE", fill="ORANGE") + + # dice 3 + if dice_selected == 3: + self.draw.rectangle((165, 50, 235, 120), outline="ORANGE", fill="ORANGE") + self.draw.ellipse([(180, 60), (192, 72)], outline="BLACK", fill="BLACK") + self.draw.ellipse([(194, 79), (206, 91)], outline="BLACK", fill="BLACK") + self.draw.ellipse([(208, 98), (220, 110)], outline="BLACK", fill="BLACK") + else: + self.draw.rectangle((165, 50, 235, 120), outline="ORANGE", fill="BLACK") + self.draw.ellipse([(180, 60), (192, 72)], outline="ORANGE", fill="ORANGE") + self.draw.ellipse([(194, 79), (206, 91)], outline="ORANGE", fill="ORANGE") + self.draw.ellipse([(208, 98), (220, 110)], outline="ORANGE", fill="ORANGE") + + # dice 4 + if dice_selected == 4: + self.draw.rectangle((5, 130, 75, 200), outline="ORANGE", fill="ORANGE") + self.draw.ellipse([(20, 140), (32, 152)], outline="BLACK", fill="BLACK") + self.draw.ellipse([(20, 174), (32, 186)], outline="BLACK", fill="BLACK") + self.draw.ellipse([(48, 140), (60, 152)], outline="BLACK", fill="BLACK") + self.draw.ellipse([(48, 174), (60, 186)], outline="BLACK", fill="BLACK") + else: + self.draw.rectangle((5, 130, 75, 200), outline="ORANGE", fill="BLACK") + self.draw.ellipse([(20, 140), (32, 152)], outline="ORANGE", fill="ORANGE") + self.draw.ellipse([(20, 174), (32, 186)], outline="ORANGE", fill="ORANGE") + self.draw.ellipse([(48, 140), (60, 152)], outline="ORANGE", fill="ORANGE") + self.draw.ellipse([(48, 174), (60, 186)], outline="ORANGE", fill="ORANGE") + + # dice 5 + if dice_selected == 5: + self.draw.rectangle((85, 130, 155, 200), outline="ORANGE", fill="ORANGE") + self.draw.ellipse([(100, 140), (112, 152)], outline="BLACK", fill="BLACK") + self.draw.ellipse([(100, 178), (112, 190)], outline="BLACK", fill="BLACK") + self.draw.ellipse([(114, 159), (126, 171)], outline="BLACK", fill="BLACK") + self.draw.ellipse([(128, 140), (140, 152)], outline="BLACK", fill="BLACK") + self.draw.ellipse([(128, 178), (140, 190)], outline="BLACK", fill="BLACK") + else: + self.draw.rectangle((85, 130, 155, 200), outline="ORANGE", fill="BLACK") + self.draw.ellipse([(100, 140), (112, 152)], outline="ORANGE", fill="ORANGE") + self.draw.ellipse([(100, 178), (112, 190)], outline="ORANGE", fill="ORANGE") + self.draw.ellipse([(114, 159), (126, 171)], outline="ORANGE", fill="ORANGE") + self.draw.ellipse([(128, 140), (140, 152)], outline="ORANGE", fill="ORANGE") + self.draw.ellipse([(128, 178), (140, 190)], outline="ORANGE", fill="ORANGE") + + # dice 6 + if dice_selected == 6: + self.draw.rectangle((165, 130, 235, 200), outline="ORANGE", fill="ORANGE") + self.draw.ellipse([(180, 140), (192, 152)], outline="BLACK", fill="BLACK") + self.draw.ellipse([(180, 157), (192, 169)], outline="BLACK", fill="BLACK") + self.draw.ellipse([(180, 174), (192, 186)], outline="BLACK", fill="BLACK") + self.draw.ellipse([(208, 140), (220, 152)], outline="BLACK", fill="BLACK") + self.draw.ellipse([(208, 157), (220, 169)], outline="BLACK", fill="BLACK") + self.draw.ellipse([(208, 174), (220, 186)], outline="BLACK", fill="BLACK") + else: + self.draw.rectangle((165, 130, 235, 200), outline="ORANGE", fill="BLACK") + self.draw.ellipse([(180, 140), (192, 152)], outline="ORANGE", fill="ORANGE") + self.draw.ellipse([(180, 157), (192, 169)], outline="ORANGE", fill="ORANGE") + self.draw.ellipse([(180, 174), (192, 186)], outline="ORANGE", fill="ORANGE") + self.draw.ellipse([(208, 140), (220, 152)], outline="ORANGE", fill="ORANGE") + self.draw.ellipse([(208, 157), (220, 169)], outline="ORANGE", fill="ORANGE") + self.draw.ellipse([(208, 174), (220, 186)], outline="ORANGE", fill="ORANGE") + + # bottom text + self.draw.text((18, 210), "Press Control Stick to Select", fill="ORANGE", font=View.IMPACT18) + View.DispShowImage() + + self.dice_selected = dice_selected + + def calc_seed_from_dice(self): + entropyinteger = int(self.roll_data, 6) + entropyinbytes = entropyinteger.to_bytes(32, byteorder="little") + badseedphrase_str = mnemonic_from_bytes(entropyinbytes) + badseedphrase_list = badseedphrase_str.split() + badseedphrase_list.pop(-1) + calclastwordphrasestr = " ".join(badseedphrase_list) + " abandon" + goodphrasebytes = mnemonic_to_bytes(calclastwordphrasestr, ignore_checksum=True) + goodseedphrasestr = mnemonic_from_bytes(goodphrasebytes) + seed_phrase = goodseedphrasestr.split() + + return seed_phrase + + ### + ### Display Seed Phrase + ### + + def display_seed_phrase(self, seed_phrase, bottom = "RIGHT to EXIT") -> bool: + ret_val = "" + + while True: + if len(seed_phrase) in (11,12): + ret_val = self.display_seed_phrase_12(seed_phrase, bottom) + if ret_val == "right": + return True + else: + return False + elif len(seed_phrase) in (23,24): + if ret_val == "": + ret_val = self.display_seed_phrase_24_1(seed_phrase, bottom) #first run + elif ret_val == "right-1": + ret_val = self.display_seed_phrase_24_2(seed_phrase, bottom) #first screen to second screen + elif ret_val == "left-2": + ret_val = self.display_seed_phrase_24_1(seed_phrase, bottom) #second screen back to first screen + elif ret_val == "left-1": + return False + elif ret_val == "right-2": + return True + + def display_seed_phrase_12(self, seed_phrase, bottom = "Right to Exit"): + self.draw.rectangle((0, 0, View.canvas_width, View.canvas_height), outline=0, fill=0) + + tw, th = View.draw.textsize("Selected Words", font=View.IMPACT18) + self.draw.text(((240 - tw) / 2, 2), "Selected Words", fill="ORANGE", font=View.IMPACT18) + + self.draw.text((2, 40), "1: " + seed_phrase[0] , fill="ORANGE", font=View.IMPACT23) + self.draw.text((2, 65), "2: " + seed_phrase[1] , fill="ORANGE", font=View.IMPACT23) + self.draw.text((2, 90), "3: " + seed_phrase[2] , fill="ORANGE", font=View.IMPACT23) + self.draw.text((2, 115), "4: " + seed_phrase[3] , fill="ORANGE", font=View.IMPACT23) + self.draw.text((2, 140), "5: " + seed_phrase[4] , fill="ORANGE", font=View.IMPACT23) + self.draw.text((2, 165), "6: " + seed_phrase[5] , fill="ORANGE", font=View.IMPACT23) + self.draw.text((120, 40), " 7: " + seed_phrase[6] , fill="ORANGE", font=View.IMPACT23) + self.draw.text((120, 65), " 8: " + seed_phrase[7] , fill="ORANGE", font=View.IMPACT23) + self.draw.text((120, 90), " 9: " + seed_phrase[8] , fill="ORANGE", font=View.IMPACT23) + self.draw.text((120, 115), "10: " + seed_phrase[9] , fill="ORANGE", font=View.IMPACT23) + self.draw.text((120, 140), "11: " + seed_phrase[10], fill="ORANGE", font=View.IMPACT23) + if len(seed_phrase) >= 12: + self.draw.text((120, 165), "12: " + seed_phrase[11], fill="ORANGE", font=View.IMPACT23) + + tw, th = View.draw.textsize(bottom, font=View.IMPACT18) + self.draw.text(((240 - tw) / 2, 210), bottom, fill="ORANGE", font=View.IMPACT18) + View.DispShowImage() + + input = self.buttons.wait_for([B.KEY_RIGHT, B.KEY_LEFT]) + if input == B.KEY_RIGHT: + return "right" + elif input == B.KEY_LEFT: + return "left" + + def display_seed_phrase_24_1(self, seed_phrase, bottom = "Right to Exit"): + self.draw.rectangle((0, 0, View.canvas_width, View.canvas_height), outline=0, fill=0) + + tw, th = View.draw.textsize("Selected Words (1/2)", font=View.IMPACT18) + self.draw.text(((240 - tw) / 2, 2), "Selected Words (1/2)", fill="ORANGE", font=View.IMPACT18) + + self.draw.text((2, 40), "1: " + seed_phrase[0] , fill="ORANGE", font=View.IMPACT23) + self.draw.text((2, 65), "2: " + seed_phrase[1] , fill="ORANGE", font=View.IMPACT23) + self.draw.text((2, 90), "3: " + seed_phrase[2] , fill="ORANGE", font=View.IMPACT23) + self.draw.text((2, 115), "4: " + seed_phrase[3] , fill="ORANGE", font=View.IMPACT23) + self.draw.text((2, 140), "5: " + seed_phrase[4] , fill="ORANGE", font=View.IMPACT23) + self.draw.text((2, 165), "6: " + seed_phrase[5] , fill="ORANGE", font=View.IMPACT23) + self.draw.text((120, 40), " 7: " + seed_phrase[6] , fill="ORANGE", font=View.IMPACT23) + self.draw.text((120, 65), " 8: " + seed_phrase[7] , fill="ORANGE", font=View.IMPACT23) + self.draw.text((120, 90), " 9: " + seed_phrase[8] , fill="ORANGE", font=View.IMPACT23) + self.draw.text((120, 115), "10: " + seed_phrase[9] , fill="ORANGE", font=View.IMPACT23) + self.draw.text((120, 140), "11: " + seed_phrase[10], fill="ORANGE", font=View.IMPACT23) + self.draw.text((120, 165), "12: " + seed_phrase[11], fill="ORANGE", font=View.IMPACT23) + tw, th = View.draw.textsize("Right to Continue", font=View.IMPACT18) + self.draw.text(((240 - tw) / 2, 210), "Right to Continue", fill="ORANGE", font=View.IMPACT18) + View.DispShowImage() + + input = self.buttons.wait_for([B.KEY_RIGHT, B.KEY_LEFT]) + if input == B.KEY_RIGHT: + return "right-1" + elif input == B.KEY_LEFT: + return "left-1" + + def display_seed_phrase_24_2(self, seed_phrase, bottom): + self.draw.rectangle((0, 0, View.canvas_width, View.canvas_height), outline=0, fill=0) + + tw, th = View.draw.textsize("Selected Words (2/2)", font=View.IMPACT18) + self.draw.text(((240 - tw) / 2, 2), "Selected Words (2/2)", fill="ORANGE", font=View.IMPACT18) + + self.draw.text((2, 40), "13: " + seed_phrase[12] , fill="ORANGE", font=View.IMPACT23) + self.draw.text((2, 65), "14: " + seed_phrase[13] , fill="ORANGE", font=View.IMPACT23) + self.draw.text((2, 90), "15: " + seed_phrase[14] , fill="ORANGE", font=View.IMPACT23) + self.draw.text((2, 115), "16: " + seed_phrase[15] , fill="ORANGE", font=View.IMPACT23) + self.draw.text((2, 140), "17: " + seed_phrase[16] , fill="ORANGE", font=View.IMPACT23) + self.draw.text((2, 165), "18: " + seed_phrase[17] , fill="ORANGE", font=View.IMPACT23) + self.draw.text((120, 40), "19: " + seed_phrase[18] , fill="ORANGE", font=View.IMPACT23) + self.draw.text((120, 65), "20: " + seed_phrase[19] , fill="ORANGE", font=View.IMPACT23) + self.draw.text((120, 90), "21: " + seed_phrase[20] , fill="ORANGE", font=View.IMPACT23) + self.draw.text((120, 115), "22: " + seed_phrase[21] , fill="ORANGE", font=View.IMPACT23) + self.draw.text((120, 140), "23: " + seed_phrase[22], fill="ORANGE", font=View.IMPACT23) + if len(seed_phrase) >= 24: + self.draw.text((120, 165), "24: " + seed_phrase[23], fill="ORANGE", font=View.IMPACT23) + tw, th = View.draw.textsize(bottom, font=View.IMPACT18) + self.draw.text(((240 - tw) / 2, 210), bottom, fill="ORANGE", font=View.IMPACT18) + View.DispShowImage() + + input = self.buttons.wait_for([B.KEY_RIGHT, B.KEY_LEFT]) + if input == B.KEY_RIGHT: + return "right-2" + elif input == B.KEY_LEFT: + return "left-2" + + ### + ### Utility Methods + ### + + def reset(self): + self.words.clear() + self.possible_alphabet = SeedToolsView.ALPHABET[:] + self.letters.clear() + self.letters.append(self.possible_alphabet[0]) + self.possible_words.clear() + + return + + def calc_possible_alphabet(self, new_letter = False): + if (len(self.letters) > 1 and new_letter == False) or (len(self.letters) > 0 and new_letter == True): + search_letters = self.letters[:] + if new_letter == False: + search_letters.pop() + possible_words = [i for i in SeedToolsView.SEEDWORDS if i.startswith("".join(search_letters))] + letter_num = len(search_letters) + possible_letters = [] + for word in possible_words: + if len(word)-1 >= letter_num: + possible_letters.append(word[letter_num]) + # remove duplicates and keep order + self.possible_alphabet = list(dict.fromkeys(possible_letters))[:] + else: + self.possible_alphabet = SeedToolsView.ALPHABET[:] diff --git a/views/settings_tools_view.py b/views/settings_tools_view.py new file mode 100644 index 00000000..c6cfb74f --- /dev/null +++ b/views/settings_tools_view.py @@ -0,0 +1,72 @@ +# SeedSigner file class dependencies +from view import View +from qr import QR +from buttons import B + +class SettingsToolsView(View): + + def __init__(self, controller) -> None: + View.__init__(self, controller) + + self.qr = QR() + self.donate_image = None + + ### Donate Menu Item + + def display_donate_info_screen(self): + self.draw_modal(["You can support", "SeedSigner by donating", "any amount of BTC", "Thank You!!!"], "", "(Press right for a QR code)") + return True + + def display_donate_qr(self): + self.draw_modal(["Loading..."]) + self.donate_image = self.qr.qrimage("bc1q8u3dyltlg6pu56fe7m58aqz9cwrfld0s03zlrjl0wvm9x4nfa60q2l0g97") + View.DispShowImage(self.donate_image) + return True + + ### Display Network Selection + + def display_current_network(self) -> str: + r = self.controller.menu_view.display_generic_selection_menu(["... [ Return to Settings ]", "Mainnet", "Testnet"], "Which Network?") + if r == 2: + return "main" + elif r == 3: + return "test" + else: + return "cancel" + + ### Display Wallet Selection + + def display_wallet_selection(self) ->str: + r = self.controller.menu_view.display_generic_selection_menu(["... [ Return to Settings ]", "Specter Desktop"], "Which Wallet?") + if r == 2: + return "Specter Desktop" + else: + return "cancel" + + ### + ### Version Info + ### + + def display_version_info(self): + + line1 = "SeedSigner" + line2 = "Version v" + self.controller.VERSION + line3 = "built for use with" + line4 = "Specter-desktop" + line5 = "v1.1.0 or higher" + line6 = "(Joystick RIGHT to EXIT)" + + View.draw.rectangle((0, 0, View.canvas_width, View.canvas_height), outline=0, fill=0) + tw, th = View.draw.textsize(line1, font=View.IMPACT22) + View.draw.text(((240 - tw) / 2, 20), line1, fill="ORANGE", font=View.IMPACT22) + tw, th = View.draw.textsize(line2, font=View.IMPACT22) + View.draw.text(((240 - tw) / 2, 55), line2, fill="ORANGE", font=View.IMPACT22) + tw, th = View.draw.textsize(line3, font=View.IMPACT22) + View.draw.text(((240 - tw) / 2, 90), line3, fill="ORANGE", font=View.IMPACT22) + tw, th = View.draw.textsize(line4, font=View.IMPACT22) + View.draw.text(((240 - tw) / 2, 125), line4, fill="ORANGE", font=View.IMPACT22) + tw, th = View.draw.textsize(line5, font=View.IMPACT22) + View.draw.text(((240 - tw) / 2, 160), line5, fill="ORANGE", font=View.IMPACT22) + tw, th = View.draw.textsize(line6, font=View.IMPACT18) + View.draw.text(((240 - tw) / 2, 210), line6, fill="ORANGE", font=View.IMPACT18) + View.DispShowImage() \ No newline at end of file diff --git a/views/signing_tools_view.py b/views/signing_tools_view.py new file mode 100644 index 00000000..da2f4382 --- /dev/null +++ b/views/signing_tools_view.py @@ -0,0 +1,105 @@ +# Internal file class dependencies +from view import View +from qr import QR +from buttons import Buttons, B + +# External Dependencies +from embit.bip39 import mnemonic_to_bytes +from embit.bip39 import mnemonic_from_bytes +from embit import script +from embit import bip32 +from embit import bip39 +from embit.networks import NETWORKS +from embit import psbt +from embit import ec +from binascii import unhexlify, hexlify, a2b_base64, b2a_base64 +import time + +class SigningToolsView(View): + + def __init__(self, controller, seed_storage) -> None: + View.__init__(self, controller) + self.seed_storage = seed_storage + self.qr = QR() + + ### + ### XPub + ### + + def display_xpub_qr(self, seed_phrase): + self.draw_modal(["Generating QR ..."]) + + seed = bip39.mnemonic_to_seed(' '.join(seed_phrase).strip()) + + root = bip32.HDKey.from_seed(seed, version=NETWORKS[self.seed_storage.get_network()]["xprv"]) + fingerprint = root.child(0).fingerprint + + # derive account according to bip84 + bip48_xprv = root.derive(self.seed_storage.get_hardened_derivation()) + + # corresponding master public key: + bip48_xpub = bip48_xprv.to_public() + + xpubstring = "[%s%s]%s" % ( + hexlify(fingerprint).decode('utf-8'), + self.seed_storage.get_hardened_derivation()[1:], + bip48_xpub.to_base58(NETWORKS[self.seed_storage.get_network()]["Zpub"])) + + print(xpubstring) + + xpub_image = self.qr.qrimage(xpubstring, 120) + + View.DispShowImage(xpub_image) + + ### + ### Sign Transaction + ### + + def display_signed_psbt_animated_qr(self, psbt) -> None: + self.draw_modal(["Generating QR ..."]) + + print(psbt) + images = self.qr.makeqrcodes(psbt, "Specter Desktop", 60, SigningToolsView.qr_gen_status) + + cnt = 0 + while True: + View.DispShowImage(images[cnt]) + cnt += 1 + if cnt >= len(images): + cnt = 0 + time.sleep(0.2) + if self.buttons.check_for_low(B.KEY_RIGHT): + return + + def display_transaction_information(self, signer) -> None: + self.draw.rectangle((0, 0, View.canvas_width, View.canvas_height), outline=0, fill=0) + tw, th = self.draw.textsize("Confirm last 13 chars", font=View.IMPACT22) + self.draw.text(((240 - tw) / 2, 5), "Confirm last 13 chars", fill="ORANGE", font=View.IMPACT22) + tw, th = self.draw.textsize("of the receiving address:", font=View.IMPACT22) + self.draw.text(((240 - tw) / 2, 30), "of the receiving address:", fill="ORANGE", font=View.IMPACT22) + tw, th = self.draw.textsize(signer.destinationaddress[-13:], font=View.IMPACT22) + self.draw.text(((240 - tw) / 2, 55), signer.destinationaddress[-13:], fill="ORANGE", font=View.IMPACT22) + tw, th = self.draw.textsize("Amount Sending:", font=View.IMPACT22) + self.draw.text(((240 - tw) / 2, 90), "Amount Sending:", fill="ORANGE", font=View.IMPACT22) + if signer.spend == 0: + tw, th = self.draw.textsize("Self-Transfer (not parsed)", font=View.IMPACT22) + self.draw.text(((240 - tw) / 2, 115), "Self-Transfer (not parsed)", fill="ORANGE", font=View.IMPACT22) + else: + tw, th = self.draw.textsize(str(signer.spend) + " satoshis", font=View.IMPACT22) + self.draw.text(((240 - tw) / 2, 115), str(signer.spend) + " satoshis", fill="ORANGE", font=View.IMPACT22) + tw, th = self.draw.textsize("Plus a fee of:", font=View.IMPACT22) + self.draw.text(((240 - tw) / 2, 150), "Plus a fee of:", fill="ORANGE", font=View.IMPACT22) + tw, th = self.draw.textsize(str(int(signer.fee)) + " satoshis", font=View.IMPACT22) + self.draw.text(((240 - tw) / 2, 175), str(int(signer.fee)) + " satoshis", fill="ORANGE", font=View.IMPACT22) + tw, th = self.draw.textsize("Left to Exit, Right to Continue", font=View.IMPACT18) + self.draw.text(((240 - tw) / 2, 215), "Left to Exit, Right to Continue", fill="ORANGE", font=View.IMPACT18) + View.DispShowImage() + + def qr_gen_status(percentage): + View.draw.rectangle((0, 0, View.canvas_width, View.canvas_height), outline=0, fill=0) + tw, th = View.draw.textsize("QR Generation", font=View.IMPACT25) + View.draw.text(((240 - tw) / 2, 90), "QR Generation", fill="ORANGE", font=View.IMPACT25) + tw, th = View.draw.textsize(str(round(percentage)) + "% Complete", font=View.IMPACT25) + View.draw.text(((240 - tw) / 2, 125), str(round(percentage)) + "% Complete", fill="ORANGE", font=View.IMPACT25) + View.DispShowImage() + diff --git a/views/view.py b/views/view.py new file mode 100644 index 00000000..d780295e --- /dev/null +++ b/views/view.py @@ -0,0 +1,187 @@ +# External Dependencies +from PIL import Image +from PIL import ImageDraw +from PIL import ImageFont +import ST7789 +import spidev as SPI +from multiprocessing import Queue + +### Generic View Class to Instatiate Display +### Static Class variables are used for display +### Designed to be inherited for other view classes, but not required + +class View: + + WIDTH = 240 + HEIGHT = 240 + + # Define necessart fonts + IMPACT16 = ImageFont.truetype('/usr/share/fonts/truetype/msttcorefonts/Impact.ttf', 16) + IMPACT18 = ImageFont.truetype('/usr/share/fonts/truetype/msttcorefonts/Impact.ttf', 18) + IMPACT20 = ImageFont.truetype('/usr/share/fonts/truetype/msttcorefonts/Impact.ttf', 20) + IMPACT21 = ImageFont.truetype('/usr/share/fonts/truetype/msttcorefonts/Impact.ttf', 21) + IMPACT22 = ImageFont.truetype('/usr/share/fonts/truetype/msttcorefonts/Impact.ttf', 22) + IMPACT23 = ImageFont.truetype('/usr/share/fonts/truetype/msttcorefonts/Impact.ttf', 23) + IMPACT25 = ImageFont.truetype('/usr/share/fonts/truetype/msttcorefonts/Impact.ttf', 25) + IMPACT26 = ImageFont.truetype('/usr/share/fonts/truetype/msttcorefonts/Impact.ttf', 26) + IMPACT35 = ImageFont.truetype('/usr/share/fonts/truetype/msttcorefonts/Impact.ttf', 35) + IMPACT50 = ImageFont.truetype('/usr/share/fonts/truetype/msttcorefonts/Impact.ttf', 50) + COURIERNEW38 = ImageFont.truetype('/usr/share/fonts/truetype/msttcorefonts/courbd.ttf', 38) + COURIERNEW30 = ImageFont.truetype('/usr/share/fonts/truetype/msttcorefonts/courbd.ttf', 30) + + RST = 27 + DC = 25 + BL = 24 + + controller = None + buttons = None + canvas_width = 0 + canvas_height = 0 + canvas = None + draw = None + bus = 0 + device = 0 + disp = None + + def __init__(self, controller) -> None: + + # Global Singleton + View.controller = controller + View.buttons = View.controller.buttons + + View.canvas_width = View.WIDTH + View.canvas_height = View.HEIGHT + View.canvas = Image.new('RGB', (View.canvas_width, View.canvas_height)) + View.draw = ImageDraw.Draw(View.canvas) + + # 240x240 display with hardware SPI: + View.bus = 0 + View.device = 0 + View.disp = ST7789.ST7789(SPI.SpiDev(View.bus, View.device),View.RST, View.DC, View.BL) + View.disp.Init() + + self.queue = Queue() + + def DispShowImage(image = None): + if image == None: + image = View.canvas + View.disp.ShowImage(image, 0, 0) + + def draw_modal(self, lines = [], title = "", bottom = "") -> None: + + View.draw.rectangle((0, 0, View.canvas_width, View.canvas_height), outline=0, fill=0) + + if len(title) > 0: + tw, th = View.draw.textsize(title, font=View.IMPACT22) + View.draw.text(((240 - tw) / 2, 2), title, fill="ORANGE", font=View.IMPACT22) + + if len(bottom) > 0: + tw, th = View.draw.textsize(bottom, font=View.IMPACT18) + View.draw.text(((240 - tw) / 2, 210), bottom, fill="ORANGE", font=View.IMPACT18) + + if len(lines) == 1: + tw, th = View.draw.textsize(lines[0], font=View.IMPACT26) + View.draw.text(((240 - tw) / 2, 90), lines[0], fill="ORANGE", font=View.IMPACT26) + elif len(lines) == 2: + tw, th = View.draw.textsize(lines[0], font=View.IMPACT22) + View.draw.text(((240 - tw) / 2, 90), lines[0], fill="ORANGE", font=View.IMPACT22) + tw, th = View.draw.textsize(lines[1], font=View.IMPACT22) + View.draw.text(((240 - tw) / 2, 125), lines[1], fill="ORANGE", font=View.IMPACT22) + elif len(lines) == 3: + tw, th = View.draw.textsize(lines[0], font=View.IMPACT26) + View.draw.text(((240 - tw) / 2, 55), lines[0], fill="ORANGE", font=View.IMPACT26) + tw, th = View.draw.textsize(lines[1], font=View.IMPACT22) + View.draw.text(((240 - tw) / 2, 90), lines[1], fill="ORANGE", font=View.IMPACT22) + tw, th = View.draw.textsize(lines[2], font=View.IMPACT22) + View.draw.text(((240 - tw) / 2, 125), lines[2], fill="ORANGE", font=View.IMPACT22) + elif len(lines) == 4: + tw, th = View.draw.textsize(lines[0], font=View.IMPACT22) + View.draw.text(((240 - tw) / 2, 55), lines[0], fill="ORANGE", font=View.IMPACT22) + tw, th = View.draw.textsize(lines[1], font=View.IMPACT22) + View.draw.text(((240 - tw) / 2, 90), lines[1], fill="ORANGE", font=View.IMPACT22) + tw, th = View.draw.textsize(lines[2], font=View.IMPACT22) + View.draw.text(((240 - tw) / 2, 125), lines[2], fill="ORANGE", font=View.IMPACT22) + tw, th = View.draw.textsize(lines[3], font=View.IMPACT22) + View.draw.text(((240 - tw) / 2, 160), lines[3], fill="ORANGE", font=View.IMPACT22) + + View.DispShowImage() + + return + + def draw_prompt_yes_no(self, lines = [], title = "", bottom = "") -> None: + + self.draw_prompt_custom("", "Yes ", "No ", lines, title, bottom) + return + + def draw_prompt_custom(self, a_txt, b_txt, c_txt, lines = [], title = "", bottom = "") -> None: + + View.draw.rectangle((0, 0, View.canvas_width, View.canvas_height), outline=0, fill=0) + + if len(title) > 0: + tw, th = View.draw.textsize(title, font=View.IMPACT22) + View.draw.text(((240 - tw) / 2, 2), title, fill="ORANGE", font=View.IMPACT22) + + if len(bottom) > 0: + tw, th = View.draw.textsize(bottom, font=View.IMPACT18) + View.draw.text(((240 - tw) / 2, 210), bottom, fill="ORANGE", font=View.IMPACT18) + + if len(lines) == 1: + tw, th = View.draw.textsize(lines[0], font=View.IMPACT26) + View.draw.text(((240 - tw) / 2, 90), lines[0], fill="ORANGE", font=View.IMPACT26) + elif len(lines) == 2: + tw, th = View.draw.textsize(lines[0], font=View.IMPACT22) + View.draw.text(((240 - tw) / 2, 90), lines[0], fill="ORANGE", font=View.IMPACT22) + tw, th = View.draw.textsize(lines[1], font=View.IMPACT22) + View.draw.text(((240 - tw) / 2, 125), lines[1], fill="ORANGE", font=View.IMPACT22) + elif len(lines) == 3: + tw, th = View.draw.textsize(lines[0], font=View.IMPACT26) + View.draw.text(((240 - tw) / 2, 20), lines[0], fill="ORANGE", font=View.IMPACT26) + tw, th = View.draw.textsize(lines[1], font=View.IMPACT22) + View.draw.text(((240 - tw) / 2, 90), lines[1], fill="ORANGE", font=View.IMPACT22) + tw, th = View.draw.textsize(lines[2], font=View.IMPACT22) + View.draw.text(((240 - tw) / 2, 125), lines[2], fill="ORANGE", font=View.IMPACT22) + elif len(lines) == 4: + tw, th = View.draw.textsize(lines[0], font=View.IMPACT22) + View.draw.text(((240 - tw) / 2, 20), lines[0], fill="ORANGE", font=View.IMPACT22) + tw, th = View.draw.textsize(lines[1], font=View.IMPACT22) + View.draw.text(((240 - tw) / 2, 90), lines[1], fill="ORANGE", font=View.IMPACT22) + tw, th = View.draw.textsize(lines[2], font=View.IMPACT22) + View.draw.text(((240 - tw) / 2, 125), lines[2], fill="ORANGE", font=View.IMPACT22) + tw, th = View.draw.textsize(lines[3], font=View.IMPACT22) + View.draw.text(((240 - tw) / 2, 160), lines[3], fill="ORANGE", font=View.IMPACT22) + + a_x_offset = 240 - View.IMPACT25.getsize(a_txt)[0] + View.draw.text((a_x_offset, 39 + 0), a_txt, fill="ORANGE", font=View.IMPACT25) + + b_x_offset = 240 - View.IMPACT25.getsize(b_txt)[0] + View.draw.text((b_x_offset , 39 + 60), b_txt, fill="ORANGE", font=View.IMPACT25) + + c_x_offset = 240 - View.IMPACT25.getsize(c_txt)[0] + View.draw.text((c_x_offset , 39 + 120), c_txt, fill="ORANGE", font=View.IMPACT25) + + View.DispShowImage() + + return + + ### + ### Power Off Screen + ### + + def display_power_off_screen(self): + + View.draw.rectangle((0, 0, View.canvas_width, View.canvas_height), outline=0, fill=0) + + line1 = "Powering Down..." + line2 = "Please wait about" + line3 = "30 seconds before" + line4 = "disconnecting power." + + tw, th = View.draw.textsize(line1, font=View.IMPACT22) + View.draw.text(((240-tw)/2, 45), line1, fill="ORANGE", font=View.IMPACT22) + tw, th = View.draw.textsize(line2, font=View.IMPACT20) + View.draw.text(((240-tw)/2, 100), line2, fill="ORANGE", font=View.IMPACT20) + tw, th = View.draw.textsize(line3, font=View.IMPACT20) + View.draw.text(((240-tw)/2, 130), line3, fill="ORANGE", font=View.IMPACT20) + tw, th = View.draw.textsize(line4, font=View.IMPACT20) + View.draw.text(((240-tw)/2, 160), line4, fill="ORANGE", font=View.IMPACT20) + View.DispShowImage()