2018-06-13 17:04:18 +00:00
|
|
|
from . import messages as proto
|
2018-08-21 13:58:26 +00:00
|
|
|
from .protobuf import dict_to_proto
|
2018-08-21 14:21:49 +00:00
|
|
|
from .tools import CallException, dict_from_camelcase, expect, normalize_nfc
|
2018-06-13 17:04:18 +00:00
|
|
|
|
|
|
|
|
2018-06-25 15:51:09 +00:00
|
|
|
@expect(proto.LiskAddress, field="address")
|
2018-06-13 17:04:18 +00:00
|
|
|
def get_address(client, n, show_display=False):
|
|
|
|
return client.call(proto.LiskGetAddress(address_n=n, show_display=show_display))
|
|
|
|
|
|
|
|
|
|
|
|
@expect(proto.LiskPublicKey)
|
|
|
|
def get_public_key(client, n, show_display=False):
|
|
|
|
return client.call(proto.LiskGetPublicKey(address_n=n, show_display=show_display))
|
|
|
|
|
|
|
|
|
|
|
|
@expect(proto.LiskMessageSignature)
|
|
|
|
def sign_message(client, n, message):
|
|
|
|
message = normalize_nfc(message)
|
|
|
|
return client.call(proto.LiskSignMessage(address_n=n, message=message))
|
|
|
|
|
|
|
|
|
|
|
|
def verify_message(client, pubkey, signature, message):
|
|
|
|
message = normalize_nfc(message)
|
|
|
|
try:
|
2018-08-13 16:21:24 +00:00
|
|
|
resp = client.call(
|
|
|
|
proto.LiskVerifyMessage(
|
|
|
|
signature=signature, public_key=pubkey, message=message
|
|
|
|
)
|
|
|
|
)
|
2018-06-13 17:04:18 +00:00
|
|
|
except CallException as e:
|
|
|
|
resp = e
|
|
|
|
return isinstance(resp, proto.Success)
|
|
|
|
|
|
|
|
|
2018-08-21 13:58:26 +00:00
|
|
|
RENAMES = {"lifetime": "life_time", "keysgroup": "keys_group"}
|
2018-06-13 17:04:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
@expect(proto.LiskSignedTx)
|
|
|
|
def sign_tx(client, n, transaction):
|
2018-08-21 13:58:26 +00:00
|
|
|
transaction = dict_from_camelcase(transaction, renames=RENAMES)
|
|
|
|
msg = dict_to_proto(proto.LiskTransactionCommon, transaction)
|
2018-06-13 17:04:18 +00:00
|
|
|
return client.call(proto.LiskSignTx(address_n=n, transaction=msg))
|