Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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 <path> ascii:<message>` (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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down