mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-22 14:28:07 +00:00
apps.ethereum: implement EthereumGetAddress
This commit is contained in:
parent
6e79da8df1
commit
e120faa227
13
src/apps/ethereum/__init__.py
Normal file
13
src/apps/ethereum/__init__.py
Normal 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)
|
40
src/apps/ethereum/layout_ethereum_get_address.py
Normal file
40
src/apps/ethereum/layout_ethereum_get_address.py
Normal 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)
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user