mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-26 09:28:13 +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 trezor.utils import chunks
|
||||||
|
|
||||||
from apps.eos import helpers
|
from apps.eos import helpers
|
||||||
from apps.eos.get_public_key import public_key_to_wif
|
|
||||||
from apps.eos.layout import require_confirm
|
from apps.eos.layout import require_confirm
|
||||||
|
|
||||||
if False:
|
if False:
|
||||||
@ -273,7 +272,7 @@ def authorization_fields(auth: EosAuthorization) -> List[str]:
|
|||||||
fields.append(str(auth.threshold))
|
fields.append(str(auth.threshold))
|
||||||
|
|
||||||
for i, key in enumerate(auth.keys):
|
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)
|
_weight = str(key.weight)
|
||||||
|
|
||||||
header = "Key #{}:".format(i + 1)
|
header = "Key #{}:".format(i + 1)
|
||||||
|
@ -5,7 +5,7 @@ from trezor.messages.EosPublicKey import EosPublicKey
|
|||||||
|
|
||||||
from apps.common import paths
|
from apps.common import paths
|
||||||
from apps.eos import CURVE
|
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
|
from apps.eos.layout import require_get_public_key
|
||||||
|
|
||||||
if False:
|
if False:
|
||||||
@ -14,17 +14,6 @@ if False:
|
|||||||
from apps.common import seed
|
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]:
|
def _get_public_key(node: bip32.HDNode) -> Tuple[str, bytes]:
|
||||||
seckey = node.private_key()
|
seckey = node.private_key()
|
||||||
public_key = secp256k1.publickey(seckey, True)
|
public_key = secp256k1.publickey(seckey, True)
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from trezor import wire
|
||||||
from trezor.crypto import base58
|
from trezor.crypto import base58
|
||||||
from trezor.messages.EosAsset import EosAsset
|
from trezor.messages.EosAsset import EosAsset
|
||||||
|
|
||||||
@ -61,3 +62,14 @@ def validate_full_path(path: list) -> bool:
|
|||||||
if path[4] != 0:
|
if path[4] != 0:
|
||||||
return False
|
return False
|
||||||
return True
|
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
|
from apps.common.paths import HARDENED
|
||||||
|
|
||||||
if not utils.BITCOIN_ONLY:
|
if not utils.BITCOIN_ONLY:
|
||||||
from apps.eos.get_public_key import _get_public_key, public_key_to_wif
|
from apps.eos.get_public_key import _get_public_key
|
||||||
from apps.eos.helpers import validate_full_path
|
from apps.eos.helpers import validate_full_path, public_key_to_wif
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin")
|
@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin")
|
||||||
|
Loading…
Reference in New Issue
Block a user