You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.5 KiB
53 lines
1.5 KiB
6 years ago
|
from ubinascii import hexlify
|
||
|
|
||
|
from trezor import log, wire
|
||
|
from trezor.messages.CardanoPublicKey import CardanoPublicKey
|
||
|
from trezor.messages.HDNodeType import HDNodeType
|
||
|
|
||
5 years ago
|
from apps.cardano import CURVE, seed
|
||
6 years ago
|
from apps.cardano.address import derive_address_and_node
|
||
|
from apps.common import layout, paths
|
||
|
from apps.common.seed import remove_ed25519_prefix
|
||
6 years ago
|
|
||
|
|
||
6 years ago
|
async def get_public_key(ctx, msg):
|
||
6 years ago
|
keychain = await seed.get_keychain(ctx)
|
||
|
|
||
6 years ago
|
await paths.validate_path(
|
||
5 years ago
|
ctx,
|
||
|
paths.validate_path_for_get_public_key,
|
||
|
keychain,
|
||
|
msg.address_n,
|
||
5 years ago
|
CURVE,
|
||
5 years ago
|
slip44_id=1815,
|
||
6 years ago
|
)
|
||
|
|
||
6 years ago
|
try:
|
||
6 years ago
|
key = _get_public_key(keychain, msg.address_n)
|
||
6 years ago
|
except ValueError as e:
|
||
|
if __debug__:
|
||
|
log.exception(__name__, e)
|
||
|
raise wire.ProcessError("Deriving public key failed")
|
||
|
|
||
6 years ago
|
if msg.show_display:
|
||
6 years ago
|
await layout.show_pubkey(ctx, key.node.public_key)
|
||
6 years ago
|
return key
|
||
|
|
||
|
|
||
6 years ago
|
def _get_public_key(keychain, derivation_path: list):
|
||
|
_, node = derive_address_and_node(keychain, derivation_path)
|
||
6 years ago
|
|
||
6 years ago
|
public_key = hexlify(remove_ed25519_prefix(node.public_key())).decode()
|
||
6 years ago
|
chain_code = hexlify(node.chain_code()).decode()
|
||
6 years ago
|
xpub_key = public_key + chain_code
|
||
6 years ago
|
|
||
6 years ago
|
node_type = HDNodeType(
|
||
|
depth=node.depth(),
|
||
|
child_num=node.child_num(),
|
||
|
fingerprint=node.fingerprint(),
|
||
|
chain_code=node.chain_code(),
|
||
6 years ago
|
public_key=remove_ed25519_prefix(node.public_key()),
|
||
6 years ago
|
)
|
||
|
|
||
6 years ago
|
return CardanoPublicKey(node=node_type, xpub=xpub_key)
|