From e4c8cb13156bbb04abdeada975f4667f8e1b1d30 Mon Sep 17 00:00:00 2001 From: Tomas Susanka Date: Thu, 12 Sep 2019 20:33:38 +0200 Subject: [PATCH] core: move public_key_to_wif to helpers --- core/src/apps/eos/actions/layout.py | 3 +-- core/src/apps/eos/get_public_key.py | 13 +------------ core/src/apps/eos/helpers.py | 12 ++++++++++++ core/tests/test_apps.eos.get_public_key.py | 4 ++-- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/core/src/apps/eos/actions/layout.py b/core/src/apps/eos/actions/layout.py index 921613287..f6342582a 100644 --- a/core/src/apps/eos/actions/layout.py +++ b/core/src/apps/eos/actions/layout.py @@ -8,7 +8,6 @@ from trezor.ui.text import Text from trezor.utils import chunks from apps.eos import helpers -from apps.eos.get_public_key import public_key_to_wif from apps.eos.layout import require_confirm if False: @@ -273,7 +272,7 @@ def authorization_fields(auth: EosAuthorization) -> List[str]: fields.append(str(auth.threshold)) for i, key in enumerate(auth.keys): - _key = public_key_to_wif(bytes(key.key)) + _key = helpers.public_key_to_wif(bytes(key.key)) _weight = str(key.weight) header = "Key #{}:".format(i + 1) diff --git a/core/src/apps/eos/get_public_key.py b/core/src/apps/eos/get_public_key.py index 4096bc11c..47b0496b5 100644 --- a/core/src/apps/eos/get_public_key.py +++ b/core/src/apps/eos/get_public_key.py @@ -5,7 +5,7 @@ from trezor.messages.EosPublicKey import EosPublicKey from apps.common import paths from apps.eos import CURVE -from apps.eos.helpers import base58_encode, validate_full_path +from apps.eos.helpers import public_key_to_wif, validate_full_path from apps.eos.layout import require_get_public_key if False: @@ -14,17 +14,6 @@ if False: from apps.common import seed -def public_key_to_wif(pub_key: bytes) -> str: - if pub_key[0] == 0x04 and len(pub_key) == 65: - head = b"\x03" if pub_key[64] & 0x01 else b"\x02" - compressed_pub_key = head + pub_key[1:33] - elif pub_key[0] in [0x02, 0x03] and len(pub_key) == 33: - compressed_pub_key = pub_key - else: - raise wire.DataError("invalid public key") - return base58_encode("EOS", "", compressed_pub_key) - - def _get_public_key(node: bip32.HDNode) -> Tuple[str, bytes]: seckey = node.private_key() public_key = secp256k1.publickey(seckey, True) diff --git a/core/src/apps/eos/helpers.py b/core/src/apps/eos/helpers.py index a440b8cf2..d5a8b0691 100644 --- a/core/src/apps/eos/helpers.py +++ b/core/src/apps/eos/helpers.py @@ -1,3 +1,4 @@ +from trezor import wire from trezor.crypto import base58 from trezor.messages.EosAsset import EosAsset @@ -61,3 +62,14 @@ def validate_full_path(path: list) -> bool: if path[4] != 0: return False return True + + +def public_key_to_wif(pub_key: bytes) -> str: + if pub_key[0] == 0x04 and len(pub_key) == 65: + head = b"\x03" if pub_key[64] & 0x01 else b"\x02" + compressed_pub_key = head + pub_key[1:33] + elif pub_key[0] in [0x02, 0x03] and len(pub_key) == 33: + compressed_pub_key = pub_key + else: + raise wire.DataError("invalid public key") + return base58_encode("EOS", "", compressed_pub_key) diff --git a/core/tests/test_apps.eos.get_public_key.py b/core/tests/test_apps.eos.get_public_key.py index 3ce00a187..0cb48fa55 100755 --- a/core/tests/test_apps.eos.get_public_key.py +++ b/core/tests/test_apps.eos.get_public_key.py @@ -4,8 +4,8 @@ from trezor.crypto import bip32, bip39 from apps.common.paths import HARDENED if not utils.BITCOIN_ONLY: - from apps.eos.get_public_key import _get_public_key, public_key_to_wif - from apps.eos.helpers import validate_full_path + from apps.eos.get_public_key import _get_public_key + from apps.eos.helpers import validate_full_path, public_key_to_wif @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin")