Skip to content

Commit

Permalink
Merge pull request #518 from BamaHodl/SignMessageError
Browse files Browse the repository at this point in the history
Fix unhandled exception when attempting to sign message for custom derivation address
  • Loading branch information
newtonick authored Feb 12, 2024
2 parents 213ca2b + 75d28c0 commit 558e6c3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/seedsigner/views/seed_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1928,7 +1928,9 @@ def __init__(self, derivation_path: str, message: str):
# calculate the actual receive address
addr_format = embit_utils.parse_derivation_path(derivation_path)
if not addr_format["clean_match"]:
raise NotYetImplementedView("Signing messages for custom derivation paths not supported")
self.set_redirect(Destination(NotYetImplementedView, view_args=dict(text=f"Signing messages for custom derivation paths not supported")))
self.controller.resume_main_flow = None
return

# Note: addr_format["network"] can be MAINNET or [TESTNET, REGTEST]
if self.settings.get_value(SettingsConstants.SETTING__NETWORK) not in addr_format["network"]:
Expand Down
4 changes: 3 additions & 1 deletion src/seedsigner/views/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,9 @@ def run(self):



@dataclass
class NotYetImplementedView(View):
text: str = "This is still on our to-do list!"
"""
Temporary View to use during dev.
"""
Expand All @@ -296,7 +298,7 @@ def run(self):
WarningScreen,
title="Work In Progress",
status_headline="Not Yet Implemented",
text="This is still on our to-do list!",
text=self.text,
button_data=["Back to Main Menu"],
)

Expand Down
31 changes: 30 additions & 1 deletion tests/test_flows_seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from seedsigner.gui.screens.screen import RET_CODE__BACK_BUTTON
from seedsigner.models.settings import Settings, SettingsConstants
from seedsigner.models.seed import Seed
from seedsigner.views.view import ErrorView, MainMenuView, OptionDisabledView, RemoveMicroSDWarningView, View, NetworkMismatchErrorView
from seedsigner.views.view import ErrorView, MainMenuView, OptionDisabledView, RemoveMicroSDWarningView, View, NetworkMismatchErrorView, NotYetImplementedView
from seedsigner.views import seed_views, scan_views, settings_views, tools_views


Expand Down Expand Up @@ -316,6 +316,7 @@ def test_discard_seed_flow(self):
class TestMessageSigningFlows(FlowTest):
MAINNET_DERIVATION_PATH = "m/84h/0h/0h/0/0"
TESTNET_DERIVATION_PATH = "m/84h/1h/0h/0/0"
CUSTOM_DERIVATION_PATH = "m/99h/0/0"
SHORT_MESSAGE = "I attest that I control this bitcoin address blah blah blah"
MULTIPAGE_MESSAGE = """Chancellor on brink of second bailout for banks
Expand Down Expand Up @@ -346,6 +347,10 @@ def load_multipage_message_into_decoder(self, view: View):
self.load_signmessage_into_decoder(view, self.MAINNET_DERIVATION_PATH, self.MULTIPAGE_MESSAGE)


def load_custom_derivation_into_decoder(self, view: View):
self.load_signmessage_into_decoder(view, self.CUSTOM_DERIVATION_PATH, self.SHORT_MESSAGE)


def inject_mesage_as_paged_message(self, view: View):
# Because the Screen won't actually run, we have to do the Screen's work here
from seedsigner.gui.components import reflow_text_into_pages, GUIConstants
Expand Down Expand Up @@ -520,3 +525,27 @@ def load_invalid_signmessage_qr(view: scan_views.ScanView):
])

assert self.controller.resume_main_flow is None


def test_sign_message_unsupported_derivation_flow(self):
"""
Should redirect to NotYetImplementedView if a message's derivation path isn't yet supported
"""
# Ensure message signing is enabled
self.settings.set_value(SettingsConstants.SETTING__MESSAGE_SIGNING, SettingsConstants.OPTION__ENABLED)

def expect_unsupported_derivation(load_message: Callable):
self.run_sequence([
FlowStep(MainMenuView, button_data_selection=MainMenuView.SCAN),
FlowStep(scan_views.ScanView, before_run=self.load_seed_into_decoder), # simulate read SeedQR; ret val is ignored
FlowStep(seed_views.SeedFinalizeView, button_data_selection=seed_views.SeedFinalizeView.FINALIZE),
FlowStep(seed_views.SeedOptionsView, button_data_selection=seed_views.SeedOptionsView.SIGN_MESSAGE),
FlowStep(scan_views.ScanView, before_run=load_message), # simulate read message QR; ret val is ignored
FlowStep(seed_views.SeedSignMessageStartView, is_redirect=True),
FlowStep(seed_views.NotYetImplementedView),
FlowStep(MainMenuView),
])

self.settings.set_value(SettingsConstants.SETTING__NETWORK, SettingsConstants.MAINNET)
expect_unsupported_derivation(self.load_custom_derivation_into_decoder)

0 comments on commit 558e6c3

Please sign in to comment.