mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 15:38:11 +00:00
core: move public_key_to_wif to helpers
This commit is contained in:
parent
adedb7df97
commit
e4c8cb1315
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user