From 7288700b86259b5ab94ede57f17cf83b466c09c3 Mon Sep 17 00:00:00 2001 From: Tomas Susanka Date: Fri, 11 Jan 2019 13:19:42 +0100 Subject: [PATCH] eth: add get public key --- trezorctl | 22 +++++++++++++ trezorlib/ethereum.py | 7 ++++ .../test_msg_ethereum_getaddress.py | 4 +++ .../test_msg_ethereum_getpublickey.py | 32 +++++++++++++++++++ 4 files changed, 65 insertions(+) create mode 100644 trezorlib/tests/device_tests/test_msg_ethereum_getpublickey.py diff --git a/trezorctl b/trezorctl index e3567d41d..b9cad3bd6 100755 --- a/trezorctl +++ b/trezorctl @@ -1060,6 +1060,28 @@ def ethereum_get_address(connect, address, show_display): return "0x%s" % address.hex() +@cli.command(help="Get Ethereum public node of given path.") +@click.option( + "-n", "--address", required=True, help="BIP-32 path, e.g. m/44'/60'/0'/0/0" +) +@click.option("-d", "--show-display", is_flag=True) +@click.pass_obj +def ethereum_get_public_node(connect, address, show_display): + client = connect() + address_n = tools.parse_path(address) + result = ethereum.get_public_node(client, address_n, show_display=show_display) + return { + "node": { + "depth": result.node.depth, + "fingerprint": "%08x" % result.node.fingerprint, + "child_num": result.node.child_num, + "chain_code": result.node.chain_code.hex(), + "public_key": result.node.public_key.hex(), + }, + "xpub": result.xpub, + } + + @cli.command( help='Sign (and optionally publish) Ethereum transaction. Use TO as destination address or set TO to "" for contract creation.' ) diff --git a/trezorlib/ethereum.py b/trezorlib/ethereum.py index 7dc403eb1..cad1e7e25 100644 --- a/trezorlib/ethereum.py +++ b/trezorlib/ethereum.py @@ -30,6 +30,13 @@ def get_address(client, n, show_display=False, multisig=None): return client.call(proto.EthereumGetAddress(address_n=n, show_display=show_display)) +@expect(proto.EthereumPublicKey) +def get_public_node(client, n, show_display=False): + return client.call( + proto.EthereumGetPublicKey(address_n=n, show_display=show_display) + ) + + @session def sign_tx( client, diff --git a/trezorlib/tests/device_tests/test_msg_ethereum_getaddress.py b/trezorlib/tests/device_tests/test_msg_ethereum_getaddress.py index ac7343300..07d2de6bd 100644 --- a/trezorlib/tests/device_tests/test_msg_ethereum_getaddress.py +++ b/trezorlib/tests/device_tests/test_msg_ethereum_getaddress.py @@ -46,3 +46,7 @@ class TestMsgEthereumGetaddress(TrezorTest): ethereum.get_address(self.client, [H_(44), H_(60), 0, 9999999]).hex() == "6b909b50d88c9a8e02453a87b3662e3e7a5e0cf1" ) + assert ( + ethereum.get_address(self.client, [H_(44), H_(6060), 0, 9999999]).hex() + == "98b8e926bd224764de2a0e4f4cbe1521474050af" + ) diff --git a/trezorlib/tests/device_tests/test_msg_ethereum_getpublickey.py b/trezorlib/tests/device_tests/test_msg_ethereum_getpublickey.py new file mode 100644 index 000000000..e97b260dd --- /dev/null +++ b/trezorlib/tests/device_tests/test_msg_ethereum_getpublickey.py @@ -0,0 +1,32 @@ +# This file is part of the Trezor project. +# +# Copyright (C) 2012-2018 SatoshiLabs and contributors +# +# This library is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the License along with this library. +# If not, see . + +import pytest + +from trezorlib import ethereum +from trezorlib.tools import H_ + +from .common import TrezorTest + + +@pytest.mark.ethereum +class TestMsgEthereumGetPublicKey(TrezorTest): + def test_ethereum_getpublickey(self): + self.setup_mnemonic_nopin_nopassphrase() + assert ( + ethereum.get_public_node(self.client, [H_(44), H_(60), H_(0)]).xpub + == "xpub6D54vV8eUYHMVBZCnz4SLjuiQngXURVCGKKGoJrWUDRegdMByLTJKfRs64q3UKiQCsSHJPtCQehTvERczdghS7gb8oedWSyNDtBU1zYDJtb" + )