1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-15 19:08:07 +00:00

cardano: remove sign/verify functions (#347)

This commit is contained in:
Tomas Susanka 2018-09-06 14:49:11 +02:00
parent 12a7996364
commit c0770ad131
3 changed files with 1 additions and 90 deletions

View File

@ -5,6 +5,4 @@ from trezor.messages import MessageType
def boot(): def boot():
wire.add(MessageType.CardanoGetAddress, __name__, "get_address") wire.add(MessageType.CardanoGetAddress, __name__, "get_address")
wire.add(MessageType.CardanoGetPublicKey, __name__, "get_public_key") wire.add(MessageType.CardanoGetPublicKey, __name__, "get_public_key")
wire.add(MessageType.CardanoSignMessage, __name__, "sign_message") wire.add(MessageType.CardanoSignTx, __name__, "sign_transaction")
wire.add(MessageType.CardanoVerifyMessage, __name__, "sign_transaction")
wire.add(MessageType.CardanoSignTx, __name__, "verify_message")

View File

@ -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

View File

@ -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)