diff --git a/src/seedsigner/views/seed_views.py b/src/seedsigner/views/seed_views.py index 2b86f417..16733ca8 100644 --- a/src/seedsigner/views/seed_views.py +++ b/src/seedsigner/views/seed_views.py @@ -1921,23 +1921,37 @@ class SeedSignMessageStartView(View): self.derivation_path = derivation_path self.message = message + # 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") + + # Note: addr_format["network"] can be MAINNET or [TESTNET, REGTEST] + if self.settings.get_value(SettingsConstants.SETTING__NETWORK) not in addr_format["network"]: + from seedsigner.views.view import NetworkMismatchErrorView + self.set_redirect(Destination(NetworkMismatchErrorView, view_args=dict(text=f"Current network setting ({self.settings.get_value_display_name(SettingsConstants.SETTING__NETWORK)}) doesn't match {self.derivation_path}"))) + + # cleanup. Note: We could leave this in place so the user can resume the + # flow, but for now we avoid complications and keep things simple. + self.controller.resume_main_flow = None + return + data = self.controller.sign_message_data if not data: data = {} self.controller.sign_message_data = data data["derivation_path"] = derivation_path data["message"] = message + data["addr_format"] = addr_format # May be None self.seed_num = data.get("seed_num") - - def run(self): if self.seed_num is not None: # We already know which seed we're signing with - return Destination(SeedSignMessageConfirmMessageView, skip_current_view=True) + self.set_redirect(Destination(SeedSignMessageConfirmMessageView, skip_current_view=True)) else: - return Destination(SeedSelectSeedView, view_args=dict(flow=Controller.FLOW__SIGN_MESSAGE), skip_current_view=True) + self.set_redirect(Destination(SeedSelectSeedView, view_args=dict(flow=Controller.FLOW__SIGN_MESSAGE), skip_current_view=True)) @@ -1979,34 +1993,14 @@ class SeedSignMessageConfirmAddressView(View): def __init__(self): super().__init__() data = self.controller.sign_message_data - self.seed_num = data.get("seed_num") + seed = self.controller.storage.seeds[data.get("seed_num")] self.derivation_path = data.get("derivation_path") + addr_format = data.get("addr_format") - if self.seed_num is None or not self.derivation_path: - raise Exception("Routing error: sign_message_data hasn't been set") - - # calculate the actual receive address - seed = self.controller.storage.seeds[self.seed_num] - addr_format = embit_utils.parse_derivation_path(self.derivation_path) - if not addr_format["clean_match"]: - raise Exception("Signing messages for custom derivation paths not supported") - - # Note: addr_format["network"] can be MAINNET or [TESTNET, REGTEST] - if self.settings.get_value(SettingsConstants.SETTING__NETWORK) in addr_format["network"]: - # Does nothing for MAINNET, but uses current setting to decide between TESTNET and REGTEST - addr_format["network"] = self.settings.get_value(SettingsConstants.SETTING__NETWORK) - else: - from seedsigner.views.view import NetworkMismatchErrorView - self.set_redirect(Destination(NetworkMismatchErrorView, view_args=dict(text=f"Current network setting ({self.settings.get_value_display_name(SettingsConstants.SETTING__NETWORK)}) doesn't match {self.derivation_path}"))) - - # cleanup. Note: We could leave this in place so the user can resume the - # flow, but for now we avoid complications and keep things simple. - self.controller.resume_main_flow = None - self.controller.sign_message_data = None - return - - xpub = seed.get_xpub(wallet_path=self.derivation_path, network=addr_format["network"]) - embit_network = embit_utils.get_embit_network_name(addr_format["network"]) + # Current settings will differentiate TESTNET and REGTEST (since derivation path + # alone doesn't specify which one we're using). + xpub = seed.get_xpub(wallet_path=self.derivation_path, network=self.settings.get_value(SettingsConstants.SETTING__NETWORK)) + embit_network = embit_utils.get_embit_network_name(self.settings.get_value(SettingsConstants.SETTING__NETWORK)) self.address = embit_utils.get_single_sig_address(xpub=xpub, script_type=addr_format["script_type"], index=addr_format["index"], is_change=addr_format["is_change"], embit_network=embit_network) diff --git a/tests/test_flows_seed.py b/tests/test_flows_seed.py index bb081bb3..d2ebc7d2 100644 --- a/tests/test_flows_seed.py +++ b/tests/test_flows_seed.py @@ -426,12 +426,6 @@ class TestMessageSigningFlows(FlowTest): FlowStep(MainMenuView, button_data_selection=MainMenuView.SCAN), 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.SeedSelectSeedView, button_data_selection=seed_views.SeedSelectSeedView.SCAN_SEED), - 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, is_redirect=True), - FlowStep(seed_views.SeedSignMessageConfirmMessageView, before_run=self.inject_mesage_as_paged_message, screen_return_value=0), - FlowStep(seed_views.SeedSignMessageConfirmAddressView, is_redirect=True), FlowStep(NetworkMismatchErrorView), FlowStep(settings_views.SettingsEntryUpdateSelectionView), ])