From 533de50588a0cd9224f4e34c4d02d1aa0ab86547 Mon Sep 17 00:00:00 2001 From: Andrew Kozlik Date: Tue, 16 Jun 2020 17:17:26 +0200 Subject: [PATCH] common/protob: Add GetOwnershipId message. --- common/protob/messages-bitcoin.proto | 21 ++++++++++ common/protob/messages.proto | 2 + core/src/trezor/messages/GetOwnershipId.py | 38 +++++++++++++++++++ core/src/trezor/messages/MessageType.py | 2 + core/src/trezor/messages/OwnershipId.py | 26 +++++++++++++ legacy/firmware/protob/Makefile | 2 +- .../firmware/protob/messages-bitcoin.options | 5 +++ .../src/trezorlib/messages/GetOwnershipId.py | 38 +++++++++++++++++++ python/src/trezorlib/messages/MessageType.py | 2 + python/src/trezorlib/messages/OwnershipId.py | 26 +++++++++++++ python/src/trezorlib/messages/__init__.py | 2 + 11 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 core/src/trezor/messages/GetOwnershipId.py create mode 100644 core/src/trezor/messages/OwnershipId.py create mode 100644 python/src/trezorlib/messages/GetOwnershipId.py create mode 100644 python/src/trezorlib/messages/OwnershipId.py diff --git a/common/protob/messages-bitcoin.proto b/common/protob/messages-bitcoin.proto index 9c4b67412..8b9d9b536 100644 --- a/common/protob/messages-bitcoin.proto +++ b/common/protob/messages-bitcoin.proto @@ -82,6 +82,27 @@ message Address { required string address = 1; // Coin address in Base58 encoding } +/** + * Request: Ask device for ownership identifier corresponding to scriptPubKey for address_n path + * @start + * @next OwnershipId + * @next Failure + */ +message GetOwnershipId { + repeated uint32 address_n = 1; // BIP-32 path to derive the key from master node + optional string coin_name = 2 [default='Bitcoin']; // coin to use + optional MultisigRedeemScriptType multisig = 3; // filled if we are dealing with a multisig scriptPubKey + optional InputScriptType script_type = 4 [default=SPENDADDRESS]; // used to distinguish between various address formats (non-segwit, segwit, etc.) +} + +/** + * Response: Contains the ownership identifier for the scriptPubKey and device private seed + * @end + */ +message OwnershipId { + required bytes ownership_id = 1; // ownership identifier +} + /** * Request: Ask device to sign message * @start diff --git a/common/protob/messages.proto b/common/protob/messages.proto index 127d0b3d4..0857485ce 100644 --- a/common/protob/messages.proto +++ b/common/protob/messages.proto @@ -87,6 +87,8 @@ enum MessageType { MessageType_SignMessage = 38 [(wire_in) = true]; MessageType_VerifyMessage = 39 [(wire_in) = true]; MessageType_MessageSignature = 40 [(wire_out) = true]; + MessageType_GetOwnershipId = 43 [(wire_in) = true]; + MessageType_OwnershipId = 44 [(wire_out) = true]; MessageType_GetOwnershipProof = 49 [(wire_in) = true]; MessageType_OwnershipProof = 50 [(wire_out) = true]; diff --git a/core/src/trezor/messages/GetOwnershipId.py b/core/src/trezor/messages/GetOwnershipId.py new file mode 100644 index 000000000..899190712 --- /dev/null +++ b/core/src/trezor/messages/GetOwnershipId.py @@ -0,0 +1,38 @@ +# Automatically generated by pb2py +# fmt: off +import protobuf as p + +from .MultisigRedeemScriptType import MultisigRedeemScriptType + +if __debug__: + try: + from typing import Dict, List # noqa: F401 + from typing_extensions import Literal # noqa: F401 + EnumTypeInputScriptType = Literal[0, 1, 2, 3, 4] + except ImportError: + pass + + +class GetOwnershipId(p.MessageType): + MESSAGE_WIRE_TYPE = 43 + + def __init__( + self, + address_n: List[int] = None, + coin_name: str = None, + multisig: MultisigRedeemScriptType = None, + script_type: EnumTypeInputScriptType = None, + ) -> None: + self.address_n = address_n if address_n is not None else [] + self.coin_name = coin_name + self.multisig = multisig + self.script_type = script_type + + @classmethod + def get_fields(cls) -> Dict: + return { + 1: ('address_n', p.UVarintType, p.FLAG_REPEATED), + 2: ('coin_name', p.UnicodeType, 0), # default=Bitcoin + 3: ('multisig', MultisigRedeemScriptType, 0), + 4: ('script_type', p.EnumType("InputScriptType", (0, 1, 2, 3, 4)), 0), # default=SPENDADDRESS + } diff --git a/core/src/trezor/messages/MessageType.py b/core/src/trezor/messages/MessageType.py index 4c30093b8..7a56e17be 100644 --- a/core/src/trezor/messages/MessageType.py +++ b/core/src/trezor/messages/MessageType.py @@ -55,6 +55,8 @@ Address = 30 # type: Literal[30] SignMessage = 38 # type: Literal[38] VerifyMessage = 39 # type: Literal[39] MessageSignature = 40 # type: Literal[40] +GetOwnershipId = 43 # type: Literal[43] +OwnershipId = 44 # type: Literal[44] GetOwnershipProof = 49 # type: Literal[49] OwnershipProof = 50 # type: Literal[50] CipherKeyValue = 23 # type: Literal[23] diff --git a/core/src/trezor/messages/OwnershipId.py b/core/src/trezor/messages/OwnershipId.py new file mode 100644 index 000000000..5b3bde331 --- /dev/null +++ b/core/src/trezor/messages/OwnershipId.py @@ -0,0 +1,26 @@ +# Automatically generated by pb2py +# fmt: off +import protobuf as p + +if __debug__: + try: + from typing import Dict, List # noqa: F401 + from typing_extensions import Literal # noqa: F401 + except ImportError: + pass + + +class OwnershipId(p.MessageType): + MESSAGE_WIRE_TYPE = 44 + + def __init__( + self, + ownership_id: bytes = None, + ) -> None: + self.ownership_id = ownership_id + + @classmethod + def get_fields(cls) -> Dict: + return { + 1: ('ownership_id', p.BytesType, 0), # required + } diff --git a/legacy/firmware/protob/Makefile b/legacy/firmware/protob/Makefile index 000499c53..98a630b22 100644 --- a/legacy/firmware/protob/Makefile +++ b/legacy/firmware/protob/Makefile @@ -4,7 +4,7 @@ endif SKIPPED_MESSAGES := Binance Cardano DebugMonero Eos Monero Ontology Ripple SdProtect Tezos WebAuthn \ DebugLinkRecordScreen DebugLinkReseedRandom DebugLinkShowText DebugLinkEraseSdCard DebugLinkWatchLayout \ - GetOwnershipProof OwnershipProof + GetOwnershipProof OwnershipProof GetOwnershipId OwnershipId ifeq ($(BITCOIN_ONLY), 1) SKIPPED_MESSAGES += Ethereum Lisk NEM Stellar diff --git a/legacy/firmware/protob/messages-bitcoin.options b/legacy/firmware/protob/messages-bitcoin.options index d7b6d6f23..56bae8226 100644 --- a/legacy/firmware/protob/messages-bitcoin.options +++ b/legacy/firmware/protob/messages-bitcoin.options @@ -59,3 +59,8 @@ GetOwnershipProof.commitment_data max_size:32 OwnershipProof.ownership_proof max_size:171 OwnershipProof.signature max_size:65 + +GetOwnershipId.address_n max_count:8 +GetOwnershipId.coin_name max_size:21 + +OwnershipId.ownership_id max_size:32 diff --git a/python/src/trezorlib/messages/GetOwnershipId.py b/python/src/trezorlib/messages/GetOwnershipId.py new file mode 100644 index 000000000..ef8b05b8f --- /dev/null +++ b/python/src/trezorlib/messages/GetOwnershipId.py @@ -0,0 +1,38 @@ +# Automatically generated by pb2py +# fmt: off +from .. import protobuf as p + +from .MultisigRedeemScriptType import MultisigRedeemScriptType + +if __debug__: + try: + from typing import Dict, List # noqa: F401 + from typing_extensions import Literal # noqa: F401 + EnumTypeInputScriptType = Literal[0, 1, 2, 3, 4] + except ImportError: + pass + + +class GetOwnershipId(p.MessageType): + MESSAGE_WIRE_TYPE = 43 + + def __init__( + self, + address_n: List[int] = None, + coin_name: str = None, + multisig: MultisigRedeemScriptType = None, + script_type: EnumTypeInputScriptType = None, + ) -> None: + self.address_n = address_n if address_n is not None else [] + self.coin_name = coin_name + self.multisig = multisig + self.script_type = script_type + + @classmethod + def get_fields(cls) -> Dict: + return { + 1: ('address_n', p.UVarintType, p.FLAG_REPEATED), + 2: ('coin_name', p.UnicodeType, 0), # default=Bitcoin + 3: ('multisig', MultisigRedeemScriptType, 0), + 4: ('script_type', p.EnumType("InputScriptType", (0, 1, 2, 3, 4)), 0), # default=SPENDADDRESS + } diff --git a/python/src/trezorlib/messages/MessageType.py b/python/src/trezorlib/messages/MessageType.py index a8f8f3e15..f0483ec35 100644 --- a/python/src/trezorlib/messages/MessageType.py +++ b/python/src/trezorlib/messages/MessageType.py @@ -53,6 +53,8 @@ Address = 30 # type: Literal[30] SignMessage = 38 # type: Literal[38] VerifyMessage = 39 # type: Literal[39] MessageSignature = 40 # type: Literal[40] +GetOwnershipId = 43 # type: Literal[43] +OwnershipId = 44 # type: Literal[44] GetOwnershipProof = 49 # type: Literal[49] OwnershipProof = 50 # type: Literal[50] CipherKeyValue = 23 # type: Literal[23] diff --git a/python/src/trezorlib/messages/OwnershipId.py b/python/src/trezorlib/messages/OwnershipId.py new file mode 100644 index 000000000..23d71df69 --- /dev/null +++ b/python/src/trezorlib/messages/OwnershipId.py @@ -0,0 +1,26 @@ +# Automatically generated by pb2py +# fmt: off +from .. import protobuf as p + +if __debug__: + try: + from typing import Dict, List # noqa: F401 + from typing_extensions import Literal # noqa: F401 + except ImportError: + pass + + +class OwnershipId(p.MessageType): + MESSAGE_WIRE_TYPE = 44 + + def __init__( + self, + ownership_id: bytes = None, + ) -> None: + self.ownership_id = ownership_id + + @classmethod + def get_fields(cls) -> Dict: + return { + 1: ('ownership_id', p.BytesType, 0), # required + } diff --git a/python/src/trezorlib/messages/__init__.py b/python/src/trezorlib/messages/__init__.py index d89198414..f5c29ed2c 100644 --- a/python/src/trezorlib/messages/__init__.py +++ b/python/src/trezorlib/messages/__init__.py @@ -111,6 +111,7 @@ from .GetECDHSessionKey import GetECDHSessionKey from .GetEntropy import GetEntropy from .GetFeatures import GetFeatures from .GetNextU2FCounter import GetNextU2FCounter +from .GetOwnershipId import GetOwnershipId from .GetOwnershipProof import GetOwnershipProof from .GetPublicKey import GetPublicKey from .HDNodePathType import HDNodePathType @@ -200,6 +201,7 @@ from .NEMSignedTx import NEMSignedTx from .NEMTransactionCommon import NEMTransactionCommon from .NEMTransfer import NEMTransfer from .NextU2FCounter import NextU2FCounter +from .OwnershipId import OwnershipId from .OwnershipProof import OwnershipProof from .PassphraseAck import PassphraseAck from .PassphraseRequest import PassphraseRequest