1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-14 03:30:02 +00:00

apps.ethereum: implement EthereumGetAddress

This commit is contained in:
Pavol Rusnak 2016-11-18 15:23:10 +01:00
parent 6e79da8df1
commit e120faa227
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
3 changed files with 55 additions and 0 deletions

View File

@ -0,0 +1,13 @@
from trezor.wire import register_type, protobuf_handler
from trezor.utils import unimport
from trezor.messages.wire_types import \
EthereumGetAddress
@unimport
def dispatch_EthereumGetAddress(*args, **kwargs):
from .layout_ethereum_get_address import layout_ethereum_get_address
return layout_ethereum_get_address(*args, **kwargs)
def boot():
register_type(EthereumGetAddress, protobuf_handler, dispatch_EthereumGetAddress)

View File

@ -0,0 +1,40 @@
from trezor import wire, ui
from trezor.utils import unimport
@unimport
async def layout_ethereum_get_address(msg, session_id):
from trezor.messages.EthereumAddress import EthereumAddress
from trezor.crypto.curve import secp256k1
from trezor.crypto.hashlib import sha3_256
from ..common.seed import get_node
address_n = getattr(msg, 'address_n', ())
show_display = getattr(msg, 'show_display', False)
node = await get_node(session_id, address_n)
seckey = node.private_key()
public_key = secp256k1.publickey(seckey, False) # uncompressed
address = sha3_256(public_key[1:]).digest(True)[12:] # Keccak
if show_display:
await _show_address(session_id, address)
return EthereumAddress(address=address)
async def _show_address(session_id, address):
from trezor.messages.ButtonRequestType import Address
from trezor.ui.text import Text
from ..common.confirm import require_confirm
# TODO: qr code
content = Text('Confirm address', ui.ICON_RESET,
ui.MONO, *_split_address(address))
await require_confirm(session_id, content, code=Address)
def _split_address(address):
from trezor.utils import chunks
return chunks(address, 20)

View File

@ -7,12 +7,14 @@ from trezor import wire
from apps import homescreen
from apps import management
from apps import wallet
from apps import ethereum
from apps import debug
# Initialize all applications
homescreen.boot()
management.boot()
wallet.boot()
ethereum.boot()
debug.boot()
# Change backlight to white for better visibility