mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-26 17:38:39 +00:00
wip3
This commit is contained in:
parent
ec3eea8e1b
commit
a223a0ab98
@ -5,6 +5,8 @@ package hw.trezor.messages.nostr;
|
|||||||
option java_package = "com.satoshilabs.trezor.lib.protobuf";
|
option java_package = "com.satoshilabs.trezor.lib.protobuf";
|
||||||
option java_outer_classname = "TrezorMessageNostr";
|
option java_outer_classname = "TrezorMessageNostr";
|
||||||
|
|
||||||
|
import "options.proto";
|
||||||
|
|
||||||
option (include_in_bitcoin_only) = true;
|
option (include_in_bitcoin_only) = true;
|
||||||
|
|
||||||
import "messages.proto";
|
import "messages.proto";
|
||||||
|
53
python/src/trezorlib/cli/nostr.py
Normal file
53
python/src/trezorlib/cli/nostr.py
Normal file
@ -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 <https://www.gnu.org/licenses/lgpl-3.0.html>.
|
||||||
|
|
||||||
|
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,
|
||||||
|
}
|
45
python/src/trezorlib/nostr.py
Normal file
45
python/src/trezorlib/nostr.py
Normal file
@ -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 <https://www.gnu.org/licenses/lgpl-3.0.html>.
|
||||||
|
|
||||||
|
|
||||||
|
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'],
|
||||||
|
)
|
||||||
|
)
|
Loading…
Reference in New Issue
Block a user