1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-18 13:38:12 +00:00

stellar: get address

including show_display var
This commit is contained in:
Tomas Susanka 2018-06-11 15:10:28 +02:00
parent 93571e469f
commit bcf77bd347
5 changed files with 39 additions and 15 deletions

View File

@ -18,7 +18,6 @@ async def get_address(ctx, msg):
address = node.nem_address(network) address = node.nem_address(network)
if msg.show_display: if msg.show_display:
while True: while True:
if await _show_address(ctx, address, network): if await _show_address(ctx, address, network):
break break

View File

@ -1,8 +1,14 @@
from trezor.wire import register, protobuf_workflow from trezor.wire import register, protobuf_workflow
from trezor.messages.wire_types import StellarGetAddress
from trezor.messages.wire_types import StellarGetPublicKey from trezor.messages.wire_types import StellarGetPublicKey
from trezor.messages.wire_types import StellarSignTx from trezor.messages.wire_types import StellarSignTx
def dispatch_StellarGetAddress(*args, **kwargs):
from .get_address import get_address
return get_address(*args, **kwargs)
def dispatch_StellarGetPublicKey(*args, **kwargs): def dispatch_StellarGetPublicKey(*args, **kwargs):
from .get_public_key import get_public_key from .get_public_key import get_public_key
return get_public_key(*args, **kwargs) return get_public_key(*args, **kwargs)
@ -14,5 +20,6 @@ def dispatch_StellarSignTx(*args, **kwargs):
def boot(): def boot():
register(StellarGetAddress, protobuf_workflow, dispatch_StellarGetAddress)
register(StellarGetPublicKey, protobuf_workflow, dispatch_StellarGetPublicKey) register(StellarGetPublicKey, protobuf_workflow, dispatch_StellarGetPublicKey)
register(StellarSignTx, protobuf_workflow, dispatch_StellarSignTx) register(StellarSignTx, protobuf_workflow, dispatch_StellarSignTx)

View File

@ -0,0 +1,20 @@
from apps.common import seed
from apps.common.display_address import show_address, show_qr
from apps.stellar import helpers
from trezor.messages.StellarAddress import StellarAddress
from trezor.messages.StellarGetAddress import StellarGetAddress
async def get_address(ctx, msg: StellarGetAddress):
node = await seed.derive_node(ctx, msg.address_n, helpers.STELLAR_CURVE)
pubkey = seed.remove_ed25519_public_key_prefix(node.public_key()) # todo better?
address = helpers.address_from_public_key(pubkey)
if msg.show_display:
while True:
if await show_address(ctx, address):
break
if await show_qr(ctx, address.upper()):
break
return StellarAddress(address=address)

View File

@ -1,31 +1,31 @@
from apps.common import seed from apps.common import seed
from apps.common.confirm import confirm from apps.common.confirm import confirm
from apps.common.display_address import split_address
from apps.stellar import helpers from apps.stellar import helpers
from trezor import ui from trezor import ui
from trezor.messages.StellarPublicKey import StellarPublicKey from trezor.messages.StellarPublicKey import StellarPublicKey
from trezor.messages.StellarGetPublicKey import StellarGetPublicKey from trezor.messages.StellarGetPublicKey import StellarGetPublicKey
from trezor.messages import ButtonRequestType from trezor.messages import ButtonRequestType
from trezor.ui.text import Text from trezor.ui.text import Text
from trezor.utils import chunks from ubinascii import hexlify
STELLAR_CURVE = 'ed25519'
async def get_public_key(ctx, msg: StellarGetPublicKey): async def get_public_key(ctx, msg: StellarGetPublicKey):
node = await seed.derive_node(ctx, msg.address_n, STELLAR_CURVE) node = await seed.derive_node(ctx, msg.address_n, helpers.STELLAR_CURVE)
pubkey = seed.remove_ed25519_public_key_prefix(node.public_key()) # todo better? pubkey = seed.remove_ed25519_public_key_prefix(node.public_key()) # todo better?
if msg.show_display:
while True: while True:
if await _show(ctx, helpers.address_from_public_key(pubkey)): if await _show(ctx, pubkey):
break break
return StellarPublicKey(public_key=pubkey) return StellarPublicKey(public_key=pubkey)
async def _show(ctx, address: str): async def _show(ctx, pubkey: bytes):
lines = _split_address(address) lines = split_address(hexlify(pubkey))
content = Text('Export Stellar ID', ui.ICON_RECEIVE, content = Text('Export Stellar ID', ui.ICON_RECEIVE,
ui.NORMAL, 'Share public account ID?', ui.NORMAL, 'Share public account ID?', # todo only two lines are displayed
ui.MONO, *lines, ui.MONO, *lines,
icon_color=ui.GREEN) icon_color=ui.GREEN)
@ -34,7 +34,3 @@ async def _show(ctx, address: str):
content, content,
code=ButtonRequestType.Address, code=ButtonRequestType.Address,
cancel_style=ui.BTN_KEY) cancel_style=ui.BTN_KEY)
def _split_address(address: str): # todo merge with NEM
return chunks(address, 17)

View File

@ -1,6 +1,8 @@
from trezor.crypto import base32 from trezor.crypto import base32
import ustruct import ustruct
STELLAR_CURVE = 'ed25519'
def address_from_public_key(pubkey: bytes): def address_from_public_key(pubkey: bytes):
"""Returns the base32-encoded version of public key bytes (G...)""" """Returns the base32-encoded version of public key bytes (G...)"""