1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-18 13:38:12 +00:00

feat(core): add Solana get_public_key and get_address calls

This commit is contained in:
gabrielkerekes 2023-08-01 15:48:14 +02:00
parent b927643f2b
commit e548108998
5 changed files with 83 additions and 0 deletions

View File

@ -363,6 +363,14 @@ apps.misc.get_firmware_hash
import apps.misc.get_firmware_hash
apps.misc.sign_identity
import apps.misc.sign_identity
apps.solana
import apps.solana
apps.solana.get_address
import apps.solana.get_address
apps.solana.get_public_key
import apps.solana.get_public_key
apps.solana.helpers.paths
import apps.solana.helpers.paths
apps.workflow_handlers
import apps.workflow_handlers

View File

@ -0,0 +1,4 @@
CURVE = "ed25519"
SLIP44_ID = 501
# TODO SOL: other patterns?
PATTERN = "m/44'/coin_type'/account'/address_index'"

View File

@ -0,0 +1,33 @@
from typing import TYPE_CHECKING
from trezor.crypto import base58
from apps.common.keychain import auto_keychain
if TYPE_CHECKING:
from trezor.messages import SolanaGetAddress, SolanaAddress
from apps.common.keychain import Keychain
@auto_keychain(__name__)
async def get_address(
msg: SolanaGetAddress,
keychain: Keychain,
) -> SolanaAddress:
from trezor.messages import SolanaAddress
from trezor.ui.layouts import show_address
from apps.common import paths, seed
address_n = msg.address_n # local_cache_attribute
await paths.validate_path(keychain, address_n)
node = keychain.derive(address_n)
address = base58.encode(seed.remove_ed25519_prefix(node.public_key()))
if msg.show_display:
await show_address(address, path=paths.address_n_to_str(address_n))
return SolanaAddress(address=address)

View File

@ -0,0 +1,32 @@
from typing import TYPE_CHECKING
from ubinascii import hexlify
from apps.common.keychain import auto_keychain
if TYPE_CHECKING:
from trezor.messages import SolanaGetPublicKey, SolanaPublicKey
# TODO SOL: maybe only get_address is needed?
@auto_keychain(__name__)
async def get_public_key(
msg: SolanaGetPublicKey, keychain: seed.Keychain
) -> SolanaPublicKey:
from trezor.ui.layouts import show_pubkey
from trezor.messages import HDNodeType, SolanaPublicKey
from apps.common import seed
node = keychain.derive(msg.address_n)
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()),
)
if msg.show_display:
await show_pubkey(hexlify(node.public_key).decode())
# TODO SOL: xpub?
return SolanaPublicKey(node=node_type, xpub=node.serialize_public(0))

View File

@ -186,6 +186,12 @@ def _find_message_handler_module(msg_type: int) -> str:
if msg_type == MessageType.BinanceSignTx:
return "apps.binance.sign_tx"
# solana
if msg_type == MessageType.SolanaGetPublicKey:
return "apps.solana.get_public_key"
if msg_type == MessageType.SolanaGetAddress:
return "apps.solana.get_address"
raise ValueError