From 0c3449298c39a6b872f0bccd962e8d57b5b98b2e Mon Sep 17 00:00:00 2001 From: Nick Johnson Date: Fri, 27 May 2016 07:13:23 +0100 Subject: [PATCH] Implement ethereum_sign_tx --- trezorlib/client.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/trezorlib/client.py b/trezorlib/client.py index da8074222..f2332865c 100644 --- a/trezorlib/client.py +++ b/trezorlib/client.py @@ -423,6 +423,34 @@ class ProtocolMixin(object): n = self._convert_prime(n) return self.call(proto.EthereumGetAddress(address_n=n, show_display=show_display)) + def ethereum_sign_tx(self, n, nonce, gas_price, gas_limit, to, value, data=''): + from rlp.utils import int_to_big_endian + + n = self._convert_prime(n) + + try: + self.transport.session_begin() + + response = self.call(proto.EthereumSignTx( + address_n=n, + nonce=int_to_big_endian(nonce), + gas_price=int_to_big_endian(gas_price), + gas_limit=int_to_big_endian(gas_limit), + to=to, + value=int_to_big_endian(value))) + if data: + data, chunk = data[1024:], data[:1024] + response.data_initial_chunk = chunk + response.data_length = len(data) + + while response.HasField('data_length'): + data, chunk = data[1024:], data[:1024] + response = self.call(proto.EthereumTxAck(data_chunk=chunk)) + + return response.signature_v, response.signature_r, response.signature_s + finally: + self.transport.session_end() + @field('entropy') @expect(proto.Entropy) def get_entropy(self, size):