From 64d9350de2157b0efca97e504c062f6feaa3de8d Mon Sep 17 00:00:00 2001 From: Andrew Kozlik Date: Tue, 16 Jun 2020 17:25:45 +0200 Subject: [PATCH] core/bitcoin: Implement GetOwnershipId message. --- core/src/apps/bitcoin/__init__.py | 1 + core/src/apps/bitcoin/get_ownership_id.py | 41 +++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 core/src/apps/bitcoin/get_ownership_id.py diff --git a/core/src/apps/bitcoin/__init__.py b/core/src/apps/bitcoin/__init__.py index 38637db4b3..47154d5466 100644 --- a/core/src/apps/bitcoin/__init__.py +++ b/core/src/apps/bitcoin/__init__.py @@ -5,6 +5,7 @@ from trezor.messages import MessageType def boot() -> None: wire.add(MessageType.GetPublicKey, __name__, "get_public_key") wire.add(MessageType.GetAddress, __name__, "get_address") + wire.add(MessageType.GetOwnershipId, __name__, "get_ownership_id") wire.add(MessageType.GetOwnershipProof, __name__, "get_ownership_proof") wire.add(MessageType.SignTx, __name__, "sign_tx") wire.add(MessageType.SignMessage, __name__, "sign_message") diff --git a/core/src/apps/bitcoin/get_ownership_id.py b/core/src/apps/bitcoin/get_ownership_id.py new file mode 100644 index 0000000000..2f0d3455c6 --- /dev/null +++ b/core/src/apps/bitcoin/get_ownership_id.py @@ -0,0 +1,41 @@ +from trezor import wire +from trezor.messages.GetOwnershipId import GetOwnershipId +from trezor.messages.OwnershipId import OwnershipId + +from apps.common import coininfo +from apps.common.paths import validate_path + +from . import addresses, common, scripts +from .keychain import with_keychain +from .ownership import get_identifier + +if False: + from apps.common.seed import Keychain + + +@with_keychain +async def get_ownership_id( + ctx, msg: GetOwnershipId, keychain: Keychain, coin: coininfo.CoinInfo +) -> OwnershipId: + await validate_path( + ctx, + addresses.validate_full_path, + keychain, + msg.address_n, + coin.curve_name, + coin=coin, + script_type=msg.script_type, + ) + + if msg.script_type not in common.INTERNAL_INPUT_SCRIPT_TYPES: + raise wire.DataError("Invalid script type") + + if msg.script_type in common.SEGWIT_INPUT_SCRIPT_TYPES and not coin.segwit: + raise wire.DataError("Segwit not enabled on this coin") + + node = keychain.derive(msg.address_n) + address = addresses.get_address(msg.script_type, coin, node, msg.multisig) + script_pubkey = scripts.output_derive_script(address, coin) + ownership_id = get_identifier(script_pubkey, keychain) + + return OwnershipId(ownership_id=ownership_id)