mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-15 19:18:11 +00:00
52 lines
1.5 KiB
Python
52 lines
1.5 KiB
Python
from ubinascii import hexlify
|
|
|
|
from trezor import log, wire
|
|
from trezor.crypto import bip32
|
|
from trezor.messages.CardanoPublicKey import CardanoPublicKey
|
|
from trezor.messages.HDNodeType import HDNodeType
|
|
|
|
from .address import derive_address_and_node
|
|
|
|
from apps.common import layout, seed, storage
|
|
|
|
|
|
async def get_public_key(ctx, msg):
|
|
mnemonic = storage.get_mnemonic()
|
|
root_node = bip32.from_mnemonic_cardano(mnemonic)
|
|
|
|
try:
|
|
key = _get_public_key(root_node, msg.address_n)
|
|
except ValueError as e:
|
|
if __debug__:
|
|
log.exception(__name__, e)
|
|
raise wire.ProcessError("Deriving public key failed")
|
|
mnemonic = None
|
|
root_node = None
|
|
|
|
if msg.show_display:
|
|
await layout.show_pubkey(ctx, key.node.public_key)
|
|
return key
|
|
|
|
|
|
def _get_public_key(root_node, derivation_path: list):
|
|
_, node = derive_address_and_node(root_node, derivation_path)
|
|
|
|
public_key = hexlify(seed.remove_ed25519_prefix(node.public_key())).decode()
|
|
chain_code = hexlify(node.chain_code()).decode()
|
|
xpub_key = public_key + chain_code
|
|
|
|
# In derivation scheme v2 the passphrase is not used
|
|
root_hd_passphrase = None
|
|
|
|
node_type = HDNodeType(
|
|
depth=node.depth(),
|
|
child_num=node.child_num(),
|
|
fingerprint=node.fingerprint(),
|
|
chain_code=node.chain_code(),
|
|
public_key=seed.remove_ed25519_prefix(node.public_key()),
|
|
)
|
|
|
|
return CardanoPublicKey(
|
|
node=node_type, xpub=xpub_key, root_hd_passphrase=root_hd_passphrase
|
|
)
|