From 00258f2d4d05172e70d561974d77d45aeb0bc586 Mon Sep 17 00:00:00 2001 From: Andrew Kozlik Date: Thu, 23 Jul 2020 17:04:16 +0200 Subject: [PATCH] core/bitcoin: Support preauthorization in GetOwnershipProof message. --- core/src/apps/bitcoin/get_ownership_proof.py | 32 +++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/core/src/apps/bitcoin/get_ownership_proof.py b/core/src/apps/bitcoin/get_ownership_proof.py index 610d72e232..e96825acc4 100644 --- a/core/src/apps/bitcoin/get_ownership_proof.py +++ b/core/src/apps/bitcoin/get_ownership_proof.py @@ -14,7 +14,9 @@ from .keychain import with_keychain from .ownership import generate_proof, get_identifier if False: + from typing import Optional from apps.common.keychain import Keychain + from .authorization import CoinJoinAuthorization # Maximum number of characters per line in monospace font. _MAX_MONO_LINE = 18 @@ -22,17 +24,25 @@ _MAX_MONO_LINE = 18 @with_keychain async def get_ownership_proof( - ctx, msg: GetOwnershipProof, keychain: Keychain, coin: coininfo.CoinInfo + ctx, + msg: GetOwnershipProof, + keychain: Keychain, + coin: coininfo.CoinInfo, + authorization: Optional[CoinJoinAuthorization] = None, ) -> OwnershipProof: - await validate_path( - ctx, - addresses.validate_full_path, - keychain, - msg.address_n, - coin.curve_name, - coin=coin, - script_type=msg.script_type, - ) + if authorization: + if not authorization.check_get_ownership_proof(msg): + raise wire.ProcessError("Unauthorized operation") + else: + 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") @@ -57,7 +67,7 @@ async def get_ownership_proof( msg.ownership_ids = [ownership_id] # In order to set the "user confirmation" bit in the proof, the user must actually confirm. - if msg.user_confirmation: + if msg.user_confirmation and not authorization: text = Text("Proof of ownership", ui.ICON_CONFIG) text.normal("Do you want to create a") if not msg.commitment_data: