From a223a0ab98d157e397704c3841ee559596d258fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ioan=20Biz=C4=83u?= Date: Tue, 5 Nov 2024 14:37:31 +0100 Subject: [PATCH] wip3 --- common/protob/messages-nostr.proto | 2 ++ python/src/trezorlib/cli/nostr.py | 53 ++++++++++++++++++++++++++++++ python/src/trezorlib/nostr.py | 45 +++++++++++++++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 python/src/trezorlib/cli/nostr.py create mode 100644 python/src/trezorlib/nostr.py diff --git a/common/protob/messages-nostr.proto b/common/protob/messages-nostr.proto index 9de8ad285e..3797bd1222 100644 --- a/common/protob/messages-nostr.proto +++ b/common/protob/messages-nostr.proto @@ -5,6 +5,8 @@ package hw.trezor.messages.nostr; option java_package = "com.satoshilabs.trezor.lib.protobuf"; option java_outer_classname = "TrezorMessageNostr"; +import "options.proto"; + option (include_in_bitcoin_only) = true; import "messages.proto"; diff --git a/python/src/trezorlib/cli/nostr.py b/python/src/trezorlib/cli/nostr.py new file mode 100644 index 0000000000..f1de9b9538 --- /dev/null +++ b/python/src/trezorlib/cli/nostr.py @@ -0,0 +1,53 @@ +# This file is part of the Trezor project. +# +# Copyright (C) 2012-2024 SatoshiLabs and contributors +# +# This library is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the License along with this library. +# If not, see . + +from typing import TYPE_CHECKING, Dict + +import click + +from .. import nostr, tools +from . import with_client + +if TYPE_CHECKING: + from ..client import TrezorClient + +@click.group(name="nostr") +def cli() -> None: + pass + +@cli.command() +@click.option("-n", "--address", required=True, help="BIP-32 path") +@click.argument("event") +@with_client +def sign_event( + client: "TrezorClient", + address: str, + event: str, +) -> Dict[str, str]: + """Sign an event using address of given path.""" + + address_n = tools.parse_path(address) + + res = nostr.sign_event( + client, + address_n, + event, + ) + + return { + "address": res.address, + "signed_event": res.signed_event, + } diff --git a/python/src/trezorlib/nostr.py b/python/src/trezorlib/nostr.py new file mode 100644 index 0000000000..efc7d5cae0 --- /dev/null +++ b/python/src/trezorlib/nostr.py @@ -0,0 +1,45 @@ +# This file is part of the Trezor project. +# +# Copyright (C) 2012-2024 SatoshiLabs and contributors +# +# This library is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the License along with this library. +# If not, see . + + +import json +from typing import TYPE_CHECKING, AnyStr + +from . import messages +from .tools import expect + +if TYPE_CHECKING: + from .client import TrezorClient + from .protobuf import MessageType + from .tools import Address + + +@expect(messages.NostrMessageSignature) +def sign_event( + client: "TrezorClient", + n: "Address", + event: AnyStr, +) -> "MessageType": + event_json = json.loads(event) + return client.call( + messages.NostrSignEvent( + address_n=n, + created_at=event_json['created_at'], + kind=event_json['kind'], + tags=event_json['tags'], + content=event_json['content'], + ) + )