From c0770ad13151a97235c9395775b8ddbabd16252a Mon Sep 17 00:00:00 2001 From: Tomas Susanka Date: Thu, 6 Sep 2018 14:49:11 +0200 Subject: [PATCH] cardano: remove sign/verify functions (#347) --- src/apps/cardano/__init__.py | 4 +-- src/apps/cardano/sign_message.py | 51 ------------------------------ src/apps/cardano/verify_message.py | 36 --------------------- 3 files changed, 1 insertion(+), 90 deletions(-) delete mode 100644 src/apps/cardano/sign_message.py delete mode 100644 src/apps/cardano/verify_message.py diff --git a/src/apps/cardano/__init__.py b/src/apps/cardano/__init__.py index b571fca0b8..fc1f1328cd 100644 --- a/src/apps/cardano/__init__.py +++ b/src/apps/cardano/__init__.py @@ -5,6 +5,4 @@ from trezor.messages import MessageType def boot(): wire.add(MessageType.CardanoGetAddress, __name__, "get_address") wire.add(MessageType.CardanoGetPublicKey, __name__, "get_public_key") - wire.add(MessageType.CardanoSignMessage, __name__, "sign_message") - wire.add(MessageType.CardanoVerifyMessage, __name__, "sign_transaction") - wire.add(MessageType.CardanoSignTx, __name__, "verify_message") + wire.add(MessageType.CardanoSignTx, __name__, "sign_transaction") diff --git a/src/apps/cardano/sign_message.py b/src/apps/cardano/sign_message.py deleted file mode 100644 index 27ae209ba1..0000000000 --- a/src/apps/cardano/sign_message.py +++ /dev/null @@ -1,51 +0,0 @@ -from trezor import log, ui, wire -from trezor.crypto import bip32 -from trezor.crypto.curve import ed25519 -from trezor.messages.CardanoMessageSignature import CardanoMessageSignature - -from .address import _break_address_n_to_lines, derive_address_and_node -from .layout import confirm_with_pagination - -from apps.common import seed, storage - - -async def sign_message(ctx, msg): - mnemonic = storage.get_mnemonic() - root_node = bip32.from_mnemonic_cardano(mnemonic) - - try: - signature = _sign_message(root_node, msg.message, msg.address_n) - except ValueError as e: - if __debug__: - log.exception(__name__, e) - raise wire.ProcessError("Signing failed") - mnemonic = None - root_node = None - - if not await confirm_with_pagination( - ctx, msg.message, "Signing message", ui.ICON_RECEIVE, ui.GREEN - ): - raise wire.ActionCancelled("Signing cancelled") - - if not await confirm_with_pagination( - ctx, - _break_address_n_to_lines(msg.address_n), - "With address", - ui.ICON_RECEIVE, - ui.GREEN, - ): - raise wire.ActionCancelled("Signing cancelled") - - return signature - - -def _sign_message(root_node, message: str, derivation_path: list): - address, node = derive_address_and_node(root_node, derivation_path) - - signature = ed25519.sign_ext(node.private_key(), node.private_key_ext(), message) - - sig = CardanoMessageSignature() - sig.public_key = seed.remove_ed25519_prefix(node.public_key()) - sig.signature = signature - - return sig diff --git a/src/apps/cardano/verify_message.py b/src/apps/cardano/verify_message.py deleted file mode 100644 index 422e197ec2..0000000000 --- a/src/apps/cardano/verify_message.py +++ /dev/null @@ -1,36 +0,0 @@ -from ubinascii import hexlify - -from trezor import log, ui, wire -from trezor.crypto.curve import ed25519 -from trezor.messages.Failure import Failure -from trezor.messages.Success import Success - -from .layout import confirm_with_pagination - - -async def verify_message(ctx, msg): - try: - res = _verify_message(msg.public_key, msg.signature, msg.message) - except ValueError as e: - if __debug__: - log.exception(__name__, e) - raise wire.ProcessError("Verifying failed") - - if not res: - return Failure(message="Invalid signature") - - if not await confirm_with_pagination( - ctx, msg.message, "Verifying message", ui.ICON_RECEIVE, ui.GREEN - ): - raise wire.ActionCancelled("Verifying cancelled") - - if not await confirm_with_pagination( - ctx, hexlify(msg.public_key), "With public key", ui.ICON_RECEIVE, ui.GREEN - ): - raise wire.ActionCancelled("Verifying cancelled") - - return Success(message="Message verified") - - -def _verify_message(public_key: bytes, signature: bytes, message: str): - return ed25519.verify(public_key, signature, message)