mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-23 23:08:14 +00:00
Merge pull request #494 from trezor/tsusanka/cardano-sign-verify
Cardano: remove sign/verify functions
This commit is contained in:
commit
d86abc473f
@ -1,53 +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 derive_address_and_node, validate_full_path
|
||||
from .layout import confirm_with_pagination
|
||||
|
||||
from apps.common import paths, seed, storage
|
||||
|
||||
|
||||
async def sign_message(ctx, msg):
|
||||
await paths.validate_path(ctx, validate_full_path, path=msg.address_n)
|
||||
|
||||
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,
|
||||
paths.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
|
@ -1,41 +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 .address import validate_full_path
|
||||
from .layout import confirm_with_pagination
|
||||
|
||||
from apps.common import paths
|
||||
|
||||
|
||||
async def verify_message(ctx, msg):
|
||||
await paths.validate_path(ctx, validate_full_path, path=msg.address_n)
|
||||
|
||||
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)
|
Loading…
Reference in New Issue
Block a user