2018-11-08 17:15:49 +00:00
|
|
|
# This file is part of the Trezor project.
|
|
|
|
#
|
2019-05-29 16:44:09 +00:00
|
|
|
# Copyright (C) 2012-2019 SatoshiLabs and contributors
|
2018-11-08 17:15:49 +00:00
|
|
|
#
|
|
|
|
# This library is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
# as published by the Free Software Foundation.
|
|
|
|
#
|
|
|
|
# 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 License along with this library.
|
|
|
|
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
|
|
|
|
|
2020-03-24 13:18:08 +00:00
|
|
|
from . import exceptions, messages
|
2018-08-21 13:58:26 +00:00
|
|
|
from .protobuf import dict_to_proto
|
2020-03-24 13:18:08 +00:00
|
|
|
from .tools import dict_from_camelcase, expect, normalize_nfc
|
2018-06-13 17:04:18 +00:00
|
|
|
|
|
|
|
|
2020-03-24 13:18:08 +00:00
|
|
|
@expect(messages.LiskAddress, field="address")
|
2018-06-13 17:04:18 +00:00
|
|
|
def get_address(client, n, show_display=False):
|
2020-03-24 13:18:08 +00:00
|
|
|
return client.call(messages.LiskGetAddress(address_n=n, show_display=show_display))
|
2018-06-13 17:04:18 +00:00
|
|
|
|
|
|
|
|
2020-03-24 13:18:08 +00:00
|
|
|
@expect(messages.LiskPublicKey)
|
2018-06-13 17:04:18 +00:00
|
|
|
def get_public_key(client, n, show_display=False):
|
2020-03-24 13:18:08 +00:00
|
|
|
return client.call(
|
|
|
|
messages.LiskGetPublicKey(address_n=n, show_display=show_display)
|
|
|
|
)
|
2018-06-13 17:04:18 +00:00
|
|
|
|
|
|
|
|
2020-03-24 13:18:08 +00:00
|
|
|
@expect(messages.LiskMessageSignature)
|
2018-06-13 17:04:18 +00:00
|
|
|
def sign_message(client, n, message):
|
|
|
|
message = normalize_nfc(message)
|
2020-03-24 13:18:08 +00:00
|
|
|
return client.call(messages.LiskSignMessage(address_n=n, message=message))
|
2018-06-13 17:04:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
def verify_message(client, pubkey, signature, message):
|
|
|
|
message = normalize_nfc(message)
|
|
|
|
try:
|
2018-08-13 16:21:24 +00:00
|
|
|
resp = client.call(
|
2020-03-24 13:18:08 +00:00
|
|
|
messages.LiskVerifyMessage(
|
2018-08-13 16:21:24 +00:00
|
|
|
signature=signature, public_key=pubkey, message=message
|
|
|
|
)
|
|
|
|
)
|
2020-03-24 13:18:08 +00:00
|
|
|
except exceptions.TrezorFailure:
|
|
|
|
return False
|
|
|
|
return isinstance(resp, messages.Success)
|
2018-06-13 17:04:18 +00:00
|
|
|
|
|
|
|
|
2018-08-21 13:58:26 +00:00
|
|
|
RENAMES = {"lifetime": "life_time", "keysgroup": "keys_group"}
|
2018-06-13 17:04:18 +00:00
|
|
|
|
|
|
|
|
2020-03-24 13:18:08 +00:00
|
|
|
@expect(messages.LiskSignedTx)
|
2018-06-13 17:04:18 +00:00
|
|
|
def sign_tx(client, n, transaction):
|
2018-08-21 13:58:26 +00:00
|
|
|
transaction = dict_from_camelcase(transaction, renames=RENAMES)
|
2020-03-24 13:18:08 +00:00
|
|
|
msg = dict_to_proto(messages.LiskTransactionCommon, transaction)
|
|
|
|
return client.call(messages.LiskSignTx(address_n=n, transaction=msg))
|