1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-15 20:19:23 +00:00

app.lisk: fix code style

This commit is contained in:
Jan Pochyla 2018-06-07 15:48:47 +02:00
parent de552b19f5
commit 1513578737
2 changed files with 31 additions and 23 deletions

View File

@ -1,8 +1,16 @@
from .helpers import LISK_CURVE, get_address_from_public_key
from apps.wallet.sign_message import require_confirm_sign_message
from trezor.crypto.hashlib import sha256
from trezor.utils import HashWriter
from apps.common import seed
from apps.common.confirm import require_confirm
from apps.common.signverify import split_message
from apps.wallet.sign_tx.signing import write_varint
from trezor import ui
from trezor.crypto.curve import ed25519
from trezor.crypto.hashlib import sha256
from trezor.messages.LiskMessageSignature import LiskMessageSignature
from trezor.ui.text import Text
from trezor.utils import HashWriter
from .helpers import LISK_CURVE
def message_digest(message):
h = HashWriter(sha256)
@ -15,16 +23,11 @@ def message_digest(message):
async def lisk_sign_message(ctx, msg):
from trezor.messages.LiskMessageSignature import LiskMessageSignature
from trezor.crypto.curve import ed25519
from ..common import seed
message = msg.message
address_n = msg.address_n or ()
await require_confirm_sign_message(ctx, message)
address_n = msg.address_n or ()
node = await seed.derive_node(ctx, address_n, LISK_CURVE)
seckey = node.private_key()
pubkey = node.public_key()
@ -33,3 +36,9 @@ async def lisk_sign_message(ctx, msg):
signature = ed25519.sign(seckey, message_digest(message))
return LiskMessageSignature(public_key=pubkey, signature=signature)
async def require_confirm_sign_message(ctx, message):
message = split_message(message)
content = Text('Sign Lisk message', ui.ICON_DEFAULT, max_lines=5, *message)
await require_confirm(ctx, content)

View File

@ -1,20 +1,19 @@
from apps.wallet.verify_message import require_confirm_verify_message
from trezor import wire
from trezor.crypto.curve import ed25519
from trezor.messages.Success import Success
from .helpers import get_address_from_public_key
from .sign_message import message_digest
async def lisk_verify_message(ctx, msg):
from trezor.crypto.curve import ed25519
from .helpers import get_address_from_public_key
from .sign_message import message_digest
from trezor import wire
from trezor.messages.Success import Success
from trezor.messages.FailureType import ProcessError
from apps.wallet.verify_message import require_confirm_verify_message
verify = ed25519.verify(msg.public_key, msg.signature, message_digest(msg.message))
if not verify:
digest = message_digest(msg.message)
verified = ed25519.verify(msg.public_key, msg.signature, digest)
if not verified:
raise wire.ProcessError('Invalid signature')
address = get_address_from_public_key(msg.public_key)
await require_confirm_verify_message(ctx, address, msg.message)
return Success(message='Message verified')
return Success(message='Message verified')