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

tolerate "H" for hard derivation in message signing #44

Merged
merged 1 commit into from
Sep 24, 2024
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
8 changes: 4 additions & 4 deletions src/krux/pages/home_pages/sign_message_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _is_valid_derivation_path(self, derivation_path):
try:
parts = derivation_path.split("/")
return parts[0] == "m" and all(
p.endswith("'") or p.endswith("h") or p.isdigit() for p in parts[1:]
p[-1] in ("'hH") or p.isdigit() for p in parts[1:]
)
except:
return False
Expand All @@ -85,9 +85,9 @@ def get_network_from_path(self, derivation_path):
if len(parts) < 2:
return None

if parts[2] in ["0'", "0h"]:
if parts[2] in ["0'", "0h", "0H"]:
return NETWORKS[MAIN_TXT]
if parts[2] in ["1'", "1h"]:
if parts[2] in ["1'", "1h", "1H"]:
return NETWORKS[TEST_TXT]
return None

Expand All @@ -97,7 +97,7 @@ def get_script_type_from_path(self, derivation_path):
if len(parts) < 2:
return None

script_from_deriv = int(parts[1].strip("'").strip("h"))
script_from_deriv = int(parts[1].strip("'hH"))
for script_name, script_number in SINGLESIG_SCRIPT_PURPOSE.items():
if script_number == script_from_deriv:
return script_name
Expand Down
14 changes: 7 additions & 7 deletions tests/pages/home_pages/test_sign_message_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def test_sign_message_at_address(mocker, m5stickv, tdata):
BUTTON_ENTER, # Sign to QR code
BUTTON_ENTER, # Check QR code
],
"signmessage m/84h/0h/0h/0/3 ascii:a test message with a colon ':' character.",
"signmessage m/84'/0h/0H/0/3 ascii:a test message with a colon ':' character.",
None,
False,
"a test message with a colon ':' character.",
Expand All @@ -264,7 +264,7 @@ def test_sign_message_at_address(mocker, m5stickv, tdata):
BUTTON_ENTER, # Sign to QR code
BUTTON_ENTER, # Check QR code
],
"signmessage m/84h/1h/0h/0/3 ascii:A test message.",
"signmessage m/84'/1h/0H/0/3 ascii:A test message.",
None,
False,
"A test message.",
Expand All @@ -279,7 +279,7 @@ def test_sign_message_at_address(mocker, m5stickv, tdata):
BUTTON_ENTER, # Sign to QR code
BUTTON_ENTER, # Check QR code
],
"signmessage m/86h/0h/0h/0/3 ascii:a test message with a colon ':' character.",
"signmessage m/86'/0h/0H/0/3 ascii:a test message with a colon ':' character.",
None,
False,
"a test message with a colon ':' character.",
Expand All @@ -294,7 +294,7 @@ def test_sign_message_at_address(mocker, m5stickv, tdata):
BUTTON_ENTER, # Sign to QR code
BUTTON_ENTER, # Check QR code
],
"signmessage m/44h/0h/0h/0/3 ascii:a test message with a colon ':' character.",
"signmessage m/44'/0h/0H/0/3 ascii:a test message with a colon ':' character.",
None,
False,
"a test message with a colon ':' character.",
Expand All @@ -309,7 +309,7 @@ def test_sign_message_at_address(mocker, m5stickv, tdata):
BUTTON_ENTER, # Sign to QR code
BUTTON_ENTER, # Check QR code
],
"signmessage m/49h/0h/0h/0/3 ascii:a test message with a colon ':' character.",
"signmessage m/49'/0h/0H/0/3 ascii:a test message with a colon ':' character.",
None,
False,
"a test message with a colon ':' character.",
Expand All @@ -326,7 +326,7 @@ def test_sign_message_at_address(mocker, m5stickv, tdata):
# BUTTON_PAGE_PREV, # Move to Go
BUTTON_ENTER, # Go
],
"signmessage m/84h/0h/0h/0/3 ascii:A test message.",
"signmessage m/84'/0h/0H/0/3 ascii:A test message.",
None,
True, # Sign to SD
"A test message.",
Expand All @@ -347,7 +347,7 @@ def test_sign_message_at_address(mocker, m5stickv, tdata):
BUTTON_ENTER, # Go
],
None,
"A test message.\nm/84'/0'/0'/0/3\nP2WPKH",
"A test message.\nm/84'/0h/0H/0/3\nP2WPKH",
True, # Sign to SD
"A test message.",
"3. bc1qgl..cn3",
Expand Down