diff --git a/trezorctl b/trezorctl index 00e8067887..b901668f87 100755 --- a/trezorctl +++ b/trezorctl @@ -892,6 +892,17 @@ def lisk_sign_message(connect, address, message): return output +@cli.command(help='Verify message signed with Lisk address.') +@click.argument('pubkey') +@click.argument('signature') +@click.argument('message') +@click.pass_obj +def lisk_verify_message(connect, pubkey, signature, message): + signature = bytes.fromhex(signature) + pubkey = bytes.fromhex(pubkey) + return connect().lisk_verify_message(pubkey, signature, message) + + # # CoSi functions # diff --git a/trezorlib/client.py b/trezorlib/client.py index b095ab7f00..023c725817 100644 --- a/trezorlib/client.py +++ b/trezorlib/client.py @@ -643,6 +643,14 @@ class ProtocolMixin(object): message = normalize_nfc(message) return self.call(proto.LiskSignMessage(address_n=n, message=message)) + def lisk_verify_message(self, pubkey, signature, message): + message = normalize_nfc(message) + try: + resp = self.call(proto.LiskVerifyMessage(signature=signature, public_key=pubkey, message=message)) + except CallException as e: + resp = e + return isinstance(resp, proto.Success) + @field('entropy') @expect(proto.Entropy) def get_entropy(self, size): diff --git a/trezorlib/tests/device_tests/test_msg_lisk_verifymessage.py b/trezorlib/tests/device_tests/test_msg_lisk_verifymessage.py new file mode 100644 index 0000000000..ee08f83474 --- /dev/null +++ b/trezorlib/tests/device_tests/test_msg_lisk_verifymessage.py @@ -0,0 +1,51 @@ +# This file is part of the TREZOR project. +# +# Copyright (C) 2016-2017 Pavol Rusnak +# +# This library is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this library. If not, see . + +from .common import * +from trezorlib import messages as proto + + +@pytest.mark.skip_t1 +class TestMsgLiskVerifymessage(TrezorTest): + + def test_verify(self): + self.setup_mnemonic_nopin_nopassphrase() + with self.client: + self.client.set_expected_responses([ + proto.ButtonRequest(code=proto.ButtonRequestType.Other), + proto.ButtonRequest(code=proto.ButtonRequestType.Other), + proto.Success(message='Message verified') + ]) + self.client.lisk_verify_message( + unhexlify('eb56d7bbb5e8ea9269405f7a8527fe126023d1db2c973cfac6f760b60ae27294'), + unhexlify('af1d384cce25354b5af129662caed6f3514c6f1f6a206662d301fd56aa5549aa23c3f82009f213a7a4d9297015c2e5b06584273df7c42d78b4e531fe4d4fc80e'), + 'This is an example of a signed message.' + ) + + def test_verify_long(self): + self.setup_mnemonic_nopin_nopassphrase() + with self.client: + self.client.set_expected_responses([ + proto.ButtonRequest(code=proto.ButtonRequestType.Other), + proto.ButtonRequest(code=proto.ButtonRequestType.Other), + proto.Success(message='Message verified') + ]) + self.client.lisk_verify_message( + unhexlify('eb56d7bbb5e8ea9269405f7a8527fe126023d1db2c973cfac6f760b60ae27294'), + unhexlify('7b4b481f6a07a874bdd1b590cd2b933c8b571c721484d9dc303f81b22d1f3c5f55ffe0704dbfd543ff9ea3e795facda871ddb422522257d33a8fe16ab4169601'), + 'VeryLongMessage!' * 64 + )