From 5ef6ba9f25e1e2bd522507063c0e49e9300d7f20 Mon Sep 17 00:00:00 2001 From: Odudex Date: Mon, 23 Sep 2024 14:56:49 -0300 Subject: [PATCH] sign messages from different script types: tests and bugfix for 49' --- src/krux/pages/home_pages/sign_message_ui.py | 4 +- .../pages/home_pages/test_sign_message_ui.py | 51 +++++++++++++++++-- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/src/krux/pages/home_pages/sign_message_ui.py b/src/krux/pages/home_pages/sign_message_ui.py index 07b2ebc5..ea44a120 100644 --- a/src/krux/pages/home_pages/sign_message_ui.py +++ b/src/krux/pages/home_pages/sign_message_ui.py @@ -26,7 +26,7 @@ import binascii from .. import MENU_CONTINUE, LOAD_FROM_CAMERA, LOAD_FROM_SD, Menu from ..utils import Utils -from ...key import SINGLESIG_SCRIPT_PURPOSE, P2PKH, P2SH, P2WPKH, P2TR +from ...key import SINGLESIG_SCRIPT_PURPOSE, P2PKH, P2WPKH, P2TR, P2SH_P2WPKH from ...themes import theme from ...display import ( DEFAULT_PADDING, @@ -120,7 +120,7 @@ def get_bitcoin_address(self, derivation_path, script_type=""): elif script_type == P2PKH: p2pkh_script = script.p2pkh(pubkey) addr = p2pkh_script.address(network=network) - elif script_type == P2SH - P2WPKH: + elif script_type == P2SH_P2WPKH: p2wpkh_script = script.p2wpkh(pubkey) p2sh_script = script.p2sh(p2wpkh_script) addr = p2sh_script.address(network=network) diff --git a/tests/pages/home_pages/test_sign_message_ui.py b/tests/pages/home_pages/test_sign_message_ui.py index ae18c2d3..117aaecf 100644 --- a/tests/pages/home_pages/test_sign_message_ui.py +++ b/tests/pages/home_pages/test_sign_message_ui.py @@ -241,7 +241,7 @@ def test_sign_message_at_address(mocker, m5stickv, tdata): # Message content # Displayed address # Signature - ( + ( # 0 - Sign P2WPKH Mainnet [ BUTTON_ENTER, # Load from camera BUTTON_ENTER, # Confirm to sign message @@ -256,7 +256,7 @@ def test_sign_message_at_address(mocker, m5stickv, tdata): "3. bc1qgl..cn3", "IN/4LmcGRaI5sgvBP2mrTXQFvD6FecXd8La03SixPabsb/255ElRGTcXhicT3KFsNJbfQ9te909ZXeKMaqUcaPM=", ), - ( + ( # 1 - Sign P2WPKH Testnet [ BUTTON_ENTER, # Load from camera BUTTON_ENTER, # Confirm to sign message @@ -271,7 +271,52 @@ def test_sign_message_at_address(mocker, m5stickv, tdata): "3. tb1qyn..5km", "ILc30ti8OPSpCtzfj7sNnftANBCuVpyRX7pnM3iAgOk9F9IUtnXNPus0+MF12y5HKYHAB6IVYr66sLmL3Vi3oEE=", ), - ( # Save to SD card + ( # 2 - Sign P2TR Mainnet + [ + BUTTON_ENTER, # Load from camera + BUTTON_ENTER, # Confirm to sign message + BUTTON_ENTER, # Check signature + 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.", + None, + False, + "a test message with a colon ':' character.", + "3. bc1py0..ler", + "H3Z5VioeLaC0rpdI2CflUu34IANgGxum0Rr9lmCziQRfUQv+vFND+nHvxHmJZA0uvLLI1/mTEEHD2bBfN6Y2d6w=", + ), + ( # 3 - Sign Legacy Mainnet + [ + BUTTON_ENTER, # Load from camera + BUTTON_ENTER, # Confirm to sign message + BUTTON_ENTER, # Check signature + 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.", + None, + False, + "a test message with a colon ':' character.", + "3. 1MVGa1..rsJ", + "IEpq8rUwSmDxO3GgwaZ75tw3DArtHtLi08kgQuRNXdteMI5KNEAWbpzsY8gRzGkspZN4YFiRu4RNCM+IsKkWys8=", + ), + ( # 4 - Sign Nested Segwit Mainnet + [ + BUTTON_ENTER, # Load from camera + BUTTON_ENTER, # Confirm to sign message + BUTTON_ENTER, # Check signature + 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.", + None, + False, + "a test message with a colon ':' character.", + "3. 38Cahk..EAN", + "HyH8898c2S6eF8hTPGhRqLC6UQrJrhw/fdguBeFG0cCrOFkbG8TCVURXOgxXaEV93vrFlHyxNGEvL10IcsLtvvI=", + ), + ( # - Sign P2WPKH Mainnet - Save to SD card [ BUTTON_ENTER, # Confirm load from camera BUTTON_ENTER, # Confirm to sign message