From 00fb2520631967d43fc09e0b53efa1b315f80a0b Mon Sep 17 00:00:00 2001 From: Tomas Susanka Date: Thu, 17 May 2018 14:24:37 +0200 Subject: [PATCH] stellar: signing init --- src/apps/stellar/__init__.py | 7 ++ src/apps/stellar/get_public_key.py | 1 - src/apps/stellar/sign_tx.py | 112 +++++++++++++++++++++++++++++ src/apps/stellar/writers.py | 26 +++++++ 4 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 src/apps/stellar/sign_tx.py create mode 100644 src/apps/stellar/writers.py diff --git a/src/apps/stellar/__init__.py b/src/apps/stellar/__init__.py index eb8ca62500..a1a032999b 100644 --- a/src/apps/stellar/__init__.py +++ b/src/apps/stellar/__init__.py @@ -1,5 +1,6 @@ from trezor.wire import register, protobuf_workflow from trezor.messages.wire_types import StellarGetPublicKey +from trezor.messages.wire_types import StellarSignTx def dispatch_StellarGetPublicKey(*args, **kwargs): @@ -7,5 +8,11 @@ def dispatch_StellarGetPublicKey(*args, **kwargs): return get_public_key(*args, **kwargs) +def dispatch_StellarSignTx(*args, **kwargs): + from .sign_tx import sign_tx_loop + return sign_tx_loop(*args, **kwargs) + + def boot(): register(StellarGetPublicKey, protobuf_workflow, dispatch_StellarGetPublicKey) + register(StellarSignTx, protobuf_workflow, dispatch_StellarSignTx) diff --git a/src/apps/stellar/get_public_key.py b/src/apps/stellar/get_public_key.py index 4ced0caa70..9bd5958abf 100644 --- a/src/apps/stellar/get_public_key.py +++ b/src/apps/stellar/get_public_key.py @@ -49,7 +49,6 @@ def _address_from_public_key(pubkey: bytes): address.extend(pubkey) address.extend(ustruct.pack("L', n)) + + +def write_uint64(w, n: int): + write_bytes(w, ustruct.pack('>Q', n)) + + +def write_bytes(w, buf: bytearray): + w.extend(buf) + + +def write_bool(w, val: True): + if val: + write_uint32(w, 1) + else: + write_uint32(w, 0) + + +def write_pubkey(w, pubkey: bytes): + # first 4 bytes of an address are the type, there's only one type (0) + write_uint32(w, 0) + write_bytes(w, bytearray(pubkey))