mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-16 17:42:02 +00:00
core/eos: reduce code duplication
This commit is contained in:
parent
1583ea62f9
commit
414b33dbfb
@ -1,5 +1,4 @@
|
|||||||
from trezor import wire
|
from trezor import wire
|
||||||
from trezor.crypto import base58
|
|
||||||
from trezor.crypto.curve import secp256k1
|
from trezor.crypto.curve import secp256k1
|
||||||
from trezor.crypto.hashlib import ripemd160
|
from trezor.crypto.hashlib import ripemd160
|
||||||
from trezor.messages.EosGetPublicKey import EosGetPublicKey
|
from trezor.messages.EosGetPublicKey import EosGetPublicKey
|
||||||
@ -7,23 +6,19 @@ 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 validate_full_path
|
from apps.eos.helpers import base58_encode, validate_full_path
|
||||||
from apps.eos.layout import require_get_public_key
|
from apps.eos.layout import require_get_public_key
|
||||||
|
|
||||||
|
|
||||||
def _ripemd160_32(data: bytes) -> bytes:
|
|
||||||
return ripemd160(data).digest()[:4]
|
|
||||||
|
|
||||||
|
|
||||||
def _public_key_to_wif(pub_key: bytes) -> str:
|
def _public_key_to_wif(pub_key: bytes) -> str:
|
||||||
if len(pub_key) == 65:
|
if pub_key[0] == 0x04 and len(pub_key) == 65:
|
||||||
head = 0x03 if pub_key[64] & 0x01 else 0x02
|
head = b"\x03" if pub_key[64] & 0x01 else b"\x02"
|
||||||
compresed_pub_key = bytes([head]) + pub_key[1:33]
|
compressed_pub_key = head + pub_key[1:33]
|
||||||
elif len(pub_key) == 33:
|
elif pub_key[0] in [0x02, 0x03] and len(pub_key) == 33:
|
||||||
compresed_pub_key = pub_key
|
compressed_pub_key = pub_key
|
||||||
else:
|
else:
|
||||||
raise wire.DataError("invalid public key length")
|
raise wire.DataError("invalid public key")
|
||||||
return "EOS" + base58.encode_check(compresed_pub_key, _ripemd160_32)
|
return base58_encode("EOS", "", compressed_pub_key)
|
||||||
|
|
||||||
|
|
||||||
def _get_public_key(node):
|
def _get_public_key(node):
|
||||||
|
@ -7,9 +7,9 @@ from apps.common import HARDENED
|
|||||||
def base58_encode(prefix: str, sig_prefix: str, data: bytes) -> str:
|
def base58_encode(prefix: str, sig_prefix: str, data: bytes) -> str:
|
||||||
b58 = base58.encode(data + base58.ripemd160_32(data + sig_prefix.encode()))
|
b58 = base58.encode(data + base58.ripemd160_32(data + sig_prefix.encode()))
|
||||||
if sig_prefix:
|
if sig_prefix:
|
||||||
return prefix + "_" + sig_prefix + "_" + b58
|
return prefix + sig_prefix + "_" + b58
|
||||||
else:
|
else:
|
||||||
return prefix + "_" + b58
|
return prefix + b58
|
||||||
|
|
||||||
|
|
||||||
def eos_name_to_string(value) -> str:
|
def eos_name_to_string(value) -> str:
|
||||||
|
@ -36,7 +36,7 @@ async def sign_tx(ctx, msg: EosSignTx, keychain):
|
|||||||
node.private_key(), digest, True, secp256k1.CANONICAL_SIG_EOS
|
node.private_key(), digest, True, secp256k1.CANONICAL_SIG_EOS
|
||||||
)
|
)
|
||||||
|
|
||||||
return EosSignedTx(signature=base58_encode("SIG", "K1", signature))
|
return EosSignedTx(signature=base58_encode("SIG_", "K1", signature))
|
||||||
|
|
||||||
|
|
||||||
async def _init(ctx, sha, msg):
|
async def _init(ctx, sha, msg):
|
||||||
|
Loading…
Reference in New Issue
Block a user