From ad5a572b7534cc442894833bc8980f694b3ceeb7 Mon Sep 17 00:00:00 2001 From: Andrew Kozlik Date: Thu, 23 Jun 2022 09:27:48 +0200 Subject: [PATCH] chore(common): Deprecate data field in CosiCommit message. --- common/protob/messages-crypto.proto | 4 ++-- core/src/trezor/messages.py | 2 -- legacy/firmware/protob/messages-crypto.options | 2 +- python/.changelog.d/noissue.removed | 1 + python/src/trezorlib/cli/cosi.py | 12 ++++++++---- python/src/trezorlib/cosi.py | 16 +++++++++++++--- 6 files changed, 25 insertions(+), 12 deletions(-) create mode 100644 python/.changelog.d/noissue.removed diff --git a/common/protob/messages-crypto.proto b/common/protob/messages-crypto.proto index 38429790d..4953e6159 100644 --- a/common/protob/messages-crypto.proto +++ b/common/protob/messages-crypto.proto @@ -97,8 +97,8 @@ message ECDHSessionKey { * @next Failure */ message CosiCommit { - repeated uint32 address_n = 1; // BIP-32 path to derive the key from master node - optional bytes data = 2; // Data to be signed + repeated uint32 address_n = 1; // BIP-32 path to derive the key from master node + optional bytes data = 2 [deprecated=true]; // Data to be signed. Deprecated in 1.10.2, the field is not needed, since CoSi commitments are no longer deterministic. } /** diff --git a/core/src/trezor/messages.py b/core/src/trezor/messages.py index 17b6e8f04..b8d6b9aed 100644 --- a/core/src/trezor/messages.py +++ b/core/src/trezor/messages.py @@ -1928,13 +1928,11 @@ if TYPE_CHECKING: class CosiCommit(protobuf.MessageType): address_n: "list[int]" - data: "bytes | None" def __init__( self, *, address_n: "list[int] | None" = None, - data: "bytes | None" = None, ) -> None: pass diff --git a/legacy/firmware/protob/messages-crypto.options b/legacy/firmware/protob/messages-crypto.options index 36a80ff1c..c4774819c 100644 --- a/legacy/firmware/protob/messages-crypto.options +++ b/legacy/firmware/protob/messages-crypto.options @@ -6,7 +6,7 @@ CipherKeyValue.iv max_size:16 CipheredKeyValue.value max_size:1024 CosiCommit.address_n max_count:8 -CosiCommit.data max_size:32 +CosiCommit.data type:FT_IGNORE CosiCommitment.commitment max_size:32 CosiCommitment.pubkey max_size:32 diff --git a/python/.changelog.d/noissue.removed b/python/.changelog.d/noissue.removed new file mode 100644 index 000000000..5acaf6aa7 --- /dev/null +++ b/python/.changelog.d/noissue.removed @@ -0,0 +1 @@ +Remove DATA parameter from trezorctl cosi commit. diff --git a/python/src/trezorlib/cli/cosi.py b/python/src/trezorlib/cli/cosi.py index 4607e7982..d84189f99 100644 --- a/python/src/trezorlib/cli/cosi.py +++ b/python/src/trezorlib/cli/cosi.py @@ -14,7 +14,8 @@ # You should have received a copy of the License along with this library. # If not, see . -from typing import TYPE_CHECKING +import warnings +from typing import TYPE_CHECKING, Optional import click @@ -35,14 +36,17 @@ def cli() -> None: @cli.command() @click.option("-n", "--address", required=True, help=PATH_HELP) -@click.argument("data") +@click.argument("data_deprecated", required=False) @with_client def commit( - client: "TrezorClient", address: str, data: str + client: "TrezorClient", address: str, data_deprecated: Optional[str] ) -> "messages.CosiCommitment": """Ask device to commit to CoSi signing.""" + if data_deprecated is not None: + warnings.warn("'data' argument is deprecated") + address_n = tools.parse_path(address) - return cosi.commit(client, address_n, bytes.fromhex(data)) + return cosi.commit(client, address_n) @cli.command() diff --git a/python/src/trezorlib/cosi.py b/python/src/trezorlib/cosi.py index fbcf603eb..77786a90f 100644 --- a/python/src/trezorlib/cosi.py +++ b/python/src/trezorlib/cosi.py @@ -14,8 +14,9 @@ # You should have received a copy of the License along with this library. # If not, see . +import warnings from functools import reduce -from typing import TYPE_CHECKING, Iterable, List, Tuple +from typing import TYPE_CHECKING, Iterable, List, Optional, Tuple from . import _ed25519, messages from .tools import expect @@ -141,8 +142,17 @@ def sign_with_privkey( @expect(messages.CosiCommitment) -def commit(client: "TrezorClient", n: "Address", data: bytes) -> "MessageType": - return client.call(messages.CosiCommit(address_n=n, data=data)) +def commit( + client: "TrezorClient", n: "Address", data: Optional[bytes] = None +) -> "MessageType": + if data is not None: + warnings.warn( + "'data' argument is deprecated", + DeprecationWarning, + stacklevel=2, + ) + + return client.call(messages.CosiCommit(address_n=n)) @expect(messages.CosiSignature)