From d67ee164765c2eb761e1f25e1c8f6c52f396f990 Mon Sep 17 00:00:00 2001 From: tadeubas Date: Mon, 23 Oct 2023 16:47:55 -0300 Subject: [PATCH 1/2] fix screensaver button check --- src/krux/context.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/krux/context.py b/src/krux/context.py index 48bbcf413..ce6890123 100644 --- a/src/krux/context.py +++ b/src/krux/context.py @@ -93,5 +93,5 @@ def screensaver(self): anim_frame = 0 bg_color, fg_color = fg_color, bg_color - if self.input.wait_for_press(block=False) is not None: + if self.input.wait_for_button(block=False) is not None: break From 7ddb6f4b062a67da3aa8e7a69035cbb1d86805a4 Mon Sep 17 00:00:00 2001 From: tadeubas Date: Mon, 23 Oct 2023 22:17:21 -0300 Subject: [PATCH 2/2] Wallet output descriptor load from and save to SD card --- src/krux/pages/home.py | 68 +++++++++++++++++++++++++++++++++++------- src/krux/sd_card.py | 1 + 2 files changed, 58 insertions(+), 11 deletions(-) diff --git a/src/krux/pages/home.py b/src/krux/pages/home.py index eaaceead3..456b3a585 100644 --- a/src/krux/pages/home.py +++ b/src/krux/pages/home.py @@ -37,6 +37,7 @@ PUBKEY_FILE_EXTENSION, PSBT_FILE_EXTENSION, SIGNED_FILE_SUFFIX, + JSON_FILE_EXTENSION, ) # to start xpub value without the xpub/zpub/ypub prefix @@ -214,14 +215,37 @@ def wallet(self): else: self.display_wallet(self.ctx.wallet) wallet_data, qr_format = self.ctx.wallet.wallet_qr() + title = t("Wallet output descriptor") self.print_standard_qr( - wallet_data, qr_format, t("Wallet output descriptor") + wallet_data, qr_format, title ) + + # Try to save the Wallet output descriptor on the SD card + if self.has_sd_card(): + from .files_operations import SaveFile + + save_page = SaveFile(self.ctx) + save_page.save_file( + self.ctx.wallet.wallet_data, + self.ctx.wallet.label, + self.ctx.wallet.label, + title + ":", + JSON_FILE_EXTENSION, + ) return MENU_CONTINUE def _load_wallet(self): wallet_data, qr_format = self.capture_qr_code() if wallet_data is None: + # Try to read the wallet output descriptor from a file on the SD card + qr_format = FORMAT_NONE + try: + _, wallet_data = self._load_file(JSON_FILE_EXTENSION) + except OSError: + pass + + if wallet_data is None: + # Both the camera and the file on SD card failed! self.flash_text(t("Failed to load output descriptor"), theme.error_color) return MENU_CONTINUE @@ -415,29 +439,51 @@ def display_wallet(self, wallet, include_qr=True): """ about = wallet.label + "\n" if wallet.is_multisig(): - xpubs = [] - for i, xpub in enumerate(wallet.policy["cosigners"]): - xpubs.append( - str(i + 1) - + ". " - + xpub[WALLET_XPUB_START : WALLET_XPUB_START + WALLET_XPUB_DIGITS] - + ".." - + xpub[len(xpub) - WALLET_XPUB_DIGITS :] + import binascii + + fingerprints = [] + for i, key in enumerate(wallet.descriptor.keys): + fingerprints.append( + str(i + 1) + ". " + binascii.hexlify(key.fingerprint).decode() ) - about += "\n".join(xpubs) + about += "\n".join(fingerprints) else: + about += wallet.key.fingerprint_hex_str() xpub = wallet.key.xpub() about += ( - xpub[WALLET_XPUB_START : WALLET_XPUB_START + WALLET_XPUB_DIGITS] + "\n" + + xpub[WALLET_XPUB_START : WALLET_XPUB_START + WALLET_XPUB_DIGITS] + ".." + xpub[len(xpub) - WALLET_XPUB_DIGITS :] ) + if include_qr: wallet_data, qr_format = wallet.wallet_qr() self.display_qr_codes(wallet_data, qr_format, title=about) else: self.ctx.display.draw_hcentered_text(about, offset_y=DEFAULT_PADDING) + # If multisig, show loaded wallet again with all XPUB + if wallet.is_multisig(): + about = wallet.label + "\n" + xpubs = [] + for i, xpub in enumerate(wallet.policy["cosigners"]): + xpubs.append( + str(i + 1) + + ". " + + xpub[WALLET_XPUB_START : WALLET_XPUB_START + WALLET_XPUB_DIGITS] + + ".." + + xpub[len(xpub) - WALLET_XPUB_DIGITS :] + ) + about += "\n".join(xpubs) + + if include_qr: + wallet_data, qr_format = wallet.wallet_qr() + self.display_qr_codes(wallet_data, qr_format, title=about) + else: + self.ctx.input.wait_for_button() + self.ctx.display.draw_hcentered_text(about, offset_y=DEFAULT_PADDING) + def print_standard_qr(self, data, qr_format, title="", width=33): """Loads printer driver and UI""" if self.print_qr_prompt(): diff --git a/src/krux/sd_card.py b/src/krux/sd_card.py index 9fbcb0e25..2006ccc68 100644 --- a/src/krux/sd_card.py +++ b/src/krux/sd_card.py @@ -25,6 +25,7 @@ SIGNED_FILE_SUFFIX = "-signed" PSBT_FILE_EXTENSION = ".psbt" +JSON_FILE_EXTENSION = ".json" SIGNATURE_FILE_EXTENSION = ".sig" PUBKEY_FILE_EXTENSION = ".pub"