Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes #17

Merged
merged 4 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/krux/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

DER_SINGLE = "m/84h/%dh/0h"
DER_MULTI = "m/48h/%dh/0h/2h"
HARDENED_STR_REPLACE = "'"


class Key:
Expand Down Expand Up @@ -77,9 +78,11 @@ def fingerprint_hex_str(self, pretty=False):
return formatted_txt % hexlify(self.fingerprint).decode("utf-8")

def derivation_str(self, pretty=False):
"""Returns the derivation path for the Hierarchical Deterministic Wallet"""
"""Returns the derivation path for the Hierarchical Deterministic Wallet to
be displayed as string
"""
formatted_txt = t("Derivation: %s") if pretty else "%s"
return formatted_txt % self.derivation
return (formatted_txt % self.derivation).replace("h", HARDENED_STR_REPLACE)

def sign(self, message_hash):
"""Signs a message with the extended master private key"""
Expand All @@ -104,3 +107,12 @@ def pick_final_word(entropy, words):
def get_default_derivation(multisig, network):
"""Return the Krux default derivation path for single-sig or multisig"""
return (DER_MULTI if multisig else DER_SINGLE) % network["bip32"]

@staticmethod
def get_default_derivation_str(multisig, network):
"""Return the Krux default derivation path for single-sig or multisig to
be displayd as string
"""
return Key.get_default_derivation(multisig, network).replace(
"h", HARDENED_STR_REPLACE
)
21 changes: 13 additions & 8 deletions src/krux/pages/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,21 +229,26 @@ def _load_wallet(self):
% self.ctx.wallet.descriptor.to_string()
)
self.ctx.display.flash_text(t("Wallet output descriptor loaded!"))

# BlueWallet single sig descriptor without fingerprint
if (
self.ctx.wallet.descriptor.key
and not self.ctx.wallet.descriptor.key.origin
):
self.ctx.display.clear()
self.ctx.display.draw_centered_text(
t("Warning:\nIncomplete output descriptor"), theme.error_color
)
self.ctx.input.wait_for_button()

except Exception as e:
self.ctx.log.exception("Exception occurred loading wallet")
self.ctx.display.clear()
self.ctx.display.draw_centered_text(
t("Invalid wallet:\n%s") % repr(e), theme.error_color
)
self.ctx.input.wait_for_button()
if self.ctx.wallet.descriptor.key: # If single sig
if not self.ctx.wallet.descriptor.key.origin:
# Blue exports descriptors without a fingerprint
self.ctx.display.clear()
self.ctx.display.draw_centered_text(
t("Warning:\nIncomplete output descriptor"), theme.error_color
)
self.ctx.input.wait_for_button()

return MENU_CONTINUE

def addresses_menu(self):
Expand Down
11 changes: 9 additions & 2 deletions src/krux/pages/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,13 @@ def _load_key_from_words(self, words):
return MENU_CONTINUE
self.ctx.display.clear()

# Test mnemonic Checksum verification before asking for passphrase
temp_key = Key(
mnemonic,
False,
NETWORKS[Settings().bitcoin.network],
)

while True:
submenu = Menu(
self.ctx,
Expand Down Expand Up @@ -354,15 +361,15 @@ def _load_key_from_words(self, words):
(
t("Single-sig")
+ "\n"
+ Key.get_default_derivation(
+ Key.get_default_derivation_str(
False, NETWORKS[Settings().bitcoin.network]
),
lambda: MENU_EXIT,
),
(
t("Multisig")
+ "\n"
+ Key.get_default_derivation(
+ Key.get_default_derivation_str(
True, NETWORKS[Settings().bitcoin.network]
),
lambda: MENU_EXIT,
Expand Down