mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-23 06:48:16 +00:00
refactor(core): delegate EthereumGetPublicKey to bitcoin GetPublicKey
This commit is contained in:
parent
01edf3f796
commit
505e014ae1
@ -1,44 +1,21 @@
|
|||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from apps.common import paths
|
|
||||||
|
|
||||||
from .keychain import with_keychain_from_path
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from trezor.messages import EthereumGetPublicKey, EthereumPublicKey
|
from trezor.messages import EthereumGetPublicKey, EthereumPublicKey
|
||||||
from trezor.wire import Context
|
from trezor.wire import Context
|
||||||
|
|
||||||
from apps.common.keychain import Keychain
|
|
||||||
|
|
||||||
|
async def get_public_key(ctx: Context, msg: EthereumGetPublicKey) -> EthereumPublicKey:
|
||||||
@with_keychain_from_path(paths.PATTERN_BIP44_PUBKEY)
|
|
||||||
async def get_public_key(
|
|
||||||
ctx: Context, msg: EthereumGetPublicKey, keychain: Keychain
|
|
||||||
) -> EthereumPublicKey:
|
|
||||||
from ubinascii import hexlify
|
from ubinascii import hexlify
|
||||||
from trezor.messages import EthereumPublicKey, HDNodeType
|
from trezor.messages import EthereumPublicKey, GetPublicKey
|
||||||
from trezor.ui.layouts import show_pubkey
|
from trezor.ui.layouts import show_pubkey
|
||||||
from apps.common import coins
|
from apps.bitcoin import get_public_key as bitcoin_get_public_key
|
||||||
|
|
||||||
await paths.validate_path(ctx, keychain, msg.address_n)
|
|
||||||
node = keychain.derive(msg.address_n)
|
|
||||||
|
|
||||||
# we use the Bitcoin format for Ethereum xpubs
|
# we use the Bitcoin format for Ethereum xpubs
|
||||||
btc = coins.by_name("Bitcoin")
|
btc_pubkey_msg = GetPublicKey(address_n=msg.address_n)
|
||||||
node_xpub = node.serialize_public(btc.xpub_magic)
|
resp = await bitcoin_get_public_key.get_public_key(ctx, btc_pubkey_msg)
|
||||||
|
|
||||||
pubkey = node.public_key()
|
|
||||||
if pubkey[0] == 1:
|
|
||||||
pubkey = b"\x00" + pubkey[1:]
|
|
||||||
node_type = HDNodeType(
|
|
||||||
depth=node.depth(),
|
|
||||||
child_num=node.child_num(),
|
|
||||||
fingerprint=node.fingerprint(),
|
|
||||||
chain_code=node.chain_code(),
|
|
||||||
public_key=pubkey,
|
|
||||||
)
|
|
||||||
|
|
||||||
if msg.show_display:
|
if msg.show_display:
|
||||||
await show_pubkey(ctx, hexlify(pubkey).decode())
|
await show_pubkey(ctx, hexlify(resp.node.public_key).decode())
|
||||||
|
|
||||||
return EthereumPublicKey(node=node_type, xpub=node_xpub)
|
return EthereumPublicKey(node=resp.node, xpub=resp.xpub)
|
||||||
|
Loading…
Reference in New Issue
Block a user