Skip to content

Commit

Permalink
tolerate "H" for hard derivation in message signing
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean Do committed Sep 24, 2024
1 parent ef92026 commit b87bb9f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
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

0 comments on commit b87bb9f

Please sign in to comment.