diff --git a/ports/stm32/boards/Passport/modules/flows/health_check_common_flow.py b/ports/stm32/boards/Passport/modules/flows/health_check_common_flow.py index 8c43ff0fb..7e993f2ae 100644 --- a/ports/stm32/boards/Passport/modules/flows/health_check_common_flow.py +++ b/ports/stm32/boards/Passport/modules/flows/health_check_common_flow.py @@ -4,7 +4,7 @@ # health_check_common_flow.py - Scan and process a health check QR code in `crypto-request` format from flows import Flow -from wallets.utils import get_addr_type_from_string +from wallets.utils import get_addr_type_from_deriv, get_addr_type_from_string from public_constants import AF_CLASSIC @@ -20,28 +20,56 @@ def __init__(self, lines, normal_signing=False): async def validate_lines(self): from pages import ErrorPage from utils import validate_sign_text - if len(self.lines) not in [2, 3]: - await ErrorPage('{} format is invalid.'.format('Message' if self.normal_signing else 'Health check')).show() - self.set_result(None) - return - # Common function to validate the message - self.text = self.lines[0] - self.subpath = self.lines[1] + err_label = 'Message' if self.normal_signing else 'Health check' - if len(self.lines) == 3: - self.addr_type = get_addr_type_from_string(self.lines[2]) - # print('text={}'.format(self.text)) - # print('subpath={}'.format(self.subpath)) + # single-line `signmessage ascii:` (Envoy export) + # Multiline messages are preserved by joining lines back before splitting. + if self.lines and self.lines[0].startswith('signmessage '): + raw = '\n'.join(self.lines) + parts = raw.split(' ', 2) - # Validate - (subpath, error) = validate_sign_text(self.text, self.subpath) - if error is not None: - await ErrorPage(text=error).show() - self.set_result(None) - return + if len(parts) != 3 or not parts[2].startswith('ascii:'): + await ErrorPage('{} format is invalid.'.format(err_label)).show() + self.set_result(None) + return + + self.subpath = parts[1] + self.text = parts[2][len('ascii:'):] + + (subpath, error) = validate_sign_text(self.text, self.subpath) + + if error is not None: + await ErrorPage(text=error).show() + self.set_result(None) + return + + self.subpath = subpath + + derived = get_addr_type_from_deriv(self.subpath) + + if derived is not None: + self.addr_type = derived + else: + if len(self.lines) not in [2, 3]: + await ErrorPage('{} format is invalid.'.format(err_label)).show() + self.set_result(None) + return + + self.text = self.lines[0] + self.subpath = self.lines[1] + + if len(self.lines) == 3: + self.addr_type = get_addr_type_from_string(self.lines[2]) + + (subpath, error) = validate_sign_text(self.text, self.subpath) + + if error is not None: + await ErrorPage(text=error).show() + self.set_result(None) + return - self.subpath = subpath + self.subpath = subpath # User Interaction for non-health check signing if self.normal_signing: diff --git a/ports/stm32/boards/Passport/modules/flows/health_check_microsd_flow.py b/ports/stm32/boards/Passport/modules/flows/health_check_microsd_flow.py index 241df459f..40f00f82c 100644 --- a/ports/stm32/boards/Passport/modules/flows/health_check_microsd_flow.py +++ b/ports/stm32/boards/Passport/modules/flows/health_check_microsd_flow.py @@ -91,7 +91,7 @@ async def parse_message(self): self.set_result(False) return - self.lines = data.split('\n') + self.lines = data.splitlines() self.goto(self.common_flow) async def common_flow(self):