1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-17 03:48:09 +00:00

app.lisk: Add lisk_get_address and helpers

This commit is contained in:
Aleksey Popov 2018-04-16 23:03:04 +03:00 committed by Jan Pochyla
parent 59e6e49111
commit a2a861a688
4 changed files with 71 additions and 0 deletions

11
src/apps/lisk/__init__.py Normal file
View File

@ -0,0 +1,11 @@
from trezor.wire import register, protobuf_workflow
from trezor.messages.wire_types import \
LiskGetAddress
def dispatch_LiskGetAddress(*args, **kwargs):
from .get_address import layout_lisk_get_address
return layout_lisk_get_address(*args, **kwargs)
def boot():
register(LiskGetAddress, protobuf_workflow, dispatch_LiskGetAddress)

View File

@ -0,0 +1,25 @@
from apps.wallet.get_address import _show_address, _show_qr
from .helpers import LISK_CURVE, get_address_from_public_key
async def layout_lisk_get_address(ctx, msg):
from trezor.messages.LiskAddress import LiskAddress
from trezor.crypto.curve import ed25519
from ..common import seed
address_n = msg.address_n or ()
node = await seed.derive_node(ctx, address_n, LISK_CURVE)
seckey = node.private_key()
public_key = ed25519.publickey(seckey)
address = get_address_from_public_key(public_key)
if msg.show_display:
while True:
if await _show_address(ctx, address):
break
if await _show_qr(ctx, address):
break
return LiskAddress(address=address)

33
src/apps/lisk/helpers.py Normal file
View File

@ -0,0 +1,33 @@
LISK_CURVE = 'ed25519'
def get_address_from_public_key(public_key):
from trezor.crypto.hashlib import sha256
# logic from lisk-js library
# https://github.com/LiskHQ/lisk-js/blob/115e0e771e8456dc6c1d4acaabba93d975655cfe/lib/transactions/crypto/convert.js#L30
publicKeyHash = list(sha256(public_key).digest())
addressData = []
for i in range(8):
addressData.append(publicKeyHash[7 - i])
address = int.from_bytes(bytes(addressData), 'big')
return str(address) + "L"
def get_votes_count(votes):
plus, minus = [], []
for vote in votes:
plus.append(vote) if vote.startswith('+') else minus.append(vote)
return len(plus), len(minus)
def get_vote_tx_text(votes):
plus, minus = get_votes_count(votes)
text = []
if plus > 0:
text.append(_text_with_plural('Add', plus))
if minus > 0:
text.append(_text_with_plural('Remove', minus))
return text
def _text_with_plural(txt, value):
return '%s %s %s' % (txt, value, ('votes' if value != 1 else 'vote'))

View File

@ -11,6 +11,7 @@ import apps.homescreen
import apps.management import apps.management
import apps.wallet import apps.wallet
import apps.ethereum import apps.ethereum
import apps.lisk
if __debug__: if __debug__:
import apps.debug import apps.debug
else: else:
@ -21,6 +22,7 @@ apps.homescreen.boot()
apps.management.boot() apps.management.boot()
apps.wallet.boot() apps.wallet.boot()
apps.ethereum.boot() apps.ethereum.boot()
apps.lisk.boot()
if __debug__: if __debug__:
apps.debug.boot() apps.debug.boot()
else: else: