From 200a668f2ff1c4a9542cedfce1bb8fde9c1ad371 Mon Sep 17 00:00:00 2001 From: gabrielkerekes Date: Wed, 2 Aug 2023 08:25:48 +0200 Subject: [PATCH] feat(core): add basic Solana sign_tx call --- core/src/all_modules.py | 2 ++ core/src/apps/solana/sign_tx.py | 29 +++++++++++++++++++++++++++++ core/src/apps/workflow_handlers.py | 2 ++ 3 files changed, 33 insertions(+) create mode 100644 core/src/apps/solana/sign_tx.py diff --git a/core/src/all_modules.py b/core/src/all_modules.py index be1244bf24..3800766ec5 100644 --- a/core/src/all_modules.py +++ b/core/src/all_modules.py @@ -371,6 +371,8 @@ apps.solana.get_public_key import apps.solana.get_public_key apps.solana.helpers.paths import apps.solana.helpers.paths +apps.solana.sign_tx +import apps.solana.sign_tx apps.workflow_handlers import apps.workflow_handlers diff --git a/core/src/apps/solana/sign_tx.py b/core/src/apps/solana/sign_tx.py new file mode 100644 index 0000000000..bd95dbe8e1 --- /dev/null +++ b/core/src/apps/solana/sign_tx.py @@ -0,0 +1,29 @@ +from typing import TYPE_CHECKING + +from trezor.crypto import base58 + +from apps.common.keychain import auto_keychain + +if TYPE_CHECKING: + from trezor.messages import SolanaSignTx, SolanaSignedTx + + from apps.common.keychain import Keychain + + +@auto_keychain(__name__) +async def sign_tx( + msg: SolanaSignTx, + keychain: Keychain, +) -> SolanaSignedTx: + from trezor.crypto.curve import ed25519 + from trezor.messages import SolanaSignedTx + + signer_path = msg.signer_path_n + serialized_tx = msg.serialized_tx + + node = keychain.derive(signer_path) + + signature = ed25519.sign(node.private_key(), serialized_tx) + + # TODO SOL: only one signature per request? + return SolanaSignedTx(serialized_tx=serialized_tx, signature=signature) diff --git a/core/src/apps/workflow_handlers.py b/core/src/apps/workflow_handlers.py index e97cec2d40..dee4fab804 100644 --- a/core/src/apps/workflow_handlers.py +++ b/core/src/apps/workflow_handlers.py @@ -191,6 +191,8 @@ def _find_message_handler_module(msg_type: int) -> str: return "apps.solana.get_public_key" if msg_type == MessageType.SolanaGetAddress: return "apps.solana.get_address" + if msg_type == MessageType.SolanaSignTx: + return "apps.solana.sign_tx" raise ValueError