diff --git a/python/src/trezorlib/cli/nostr.py b/python/src/trezorlib/cli/nostr.py index b52ac3b8a7..a0f1b14d4a 100644 --- a/python/src/trezorlib/cli/nostr.py +++ b/python/src/trezorlib/cli/nostr.py @@ -22,10 +22,10 @@ import typing as t import click from .. import messages, nostr, tools -from . import with_client +from . import with_session if t.TYPE_CHECKING: - from ..client import TrezorClient + from ..transport.session import Session PATH_TEMPLATE = "m/44h/1237h/{}h/0/0" @@ -38,9 +38,9 @@ def cli() -> None: @cli.command() @click.option("-a", "--account", default=0, help="Account index") -@with_client +@with_session def get_pubkey( - client: "TrezorClient", + session: "Session", account: int, ) -> str: """Return the pubkey derived by the given path.""" @@ -48,7 +48,7 @@ def get_pubkey( address_n = tools.parse_path(PATH_TEMPLATE.format(account)) return nostr.get_pubkey( - client, + session, address_n, ).hex() @@ -56,9 +56,9 @@ def get_pubkey( @cli.command() @click.option("-a", "--account", default=0, help="Account index") @click.argument("event") -@with_client +@with_session def sign_event( - client: "TrezorClient", + session: "Session", account: int, event: str, ) -> dict[str, str]: @@ -69,7 +69,7 @@ def sign_event( address_n = tools.parse_path(PATH_TEMPLATE.format(account)) res = nostr.sign_event( - client, + session, messages.NostrSignEvent( address_n=address_n, created_at=event_json["created_at"], diff --git a/python/src/trezorlib/nostr.py b/python/src/trezorlib/nostr.py index 1db2c2127b..6710bc3d3d 100644 --- a/python/src/trezorlib/nostr.py +++ b/python/src/trezorlib/nostr.py @@ -20,12 +20,12 @@ from typing import TYPE_CHECKING from . import messages if TYPE_CHECKING: - from .client import TrezorClient from .tools import Address + from .transport.session import Session -def get_pubkey(client: "TrezorClient", n: "Address") -> bytes: - return client.call( +def get_pubkey(session: "Session", n: "Address") -> bytes: + return session.call( messages.NostrGetPubkey( address_n=n, ), @@ -34,7 +34,7 @@ def get_pubkey(client: "TrezorClient", n: "Address") -> bytes: def sign_event( - client: "TrezorClient", + session: "Session", sign_event: messages.NostrSignEvent, ) -> messages.NostrEventSignature: - return client.call(sign_event, expect=messages.NostrEventSignature) + return session.call(sign_event, expect=messages.NostrEventSignature) diff --git a/tests/device_tests/nostr/test_nostr.py b/tests/device_tests/nostr/test_nostr.py index 465ca256eb..cc87741238 100644 --- a/tests/device_tests/nostr/test_nostr.py +++ b/tests/device_tests/nostr/test_nostr.py @@ -20,6 +20,7 @@ from hashlib import sha256 import pytest from trezorlib import messages, nostr +from trezorlib.debuglink import SessionDebugWrapper as Session from trezorlib.tools import parse_path pytestmark = [pytest.mark.altcoin, pytest.mark.models("core")] @@ -87,9 +88,9 @@ SIGN_TEST_EVENT = messages.NostrSignEvent( @pytest.mark.parametrize("pubkey_hex,_", VECTORS) -def test_get_pubkey(client, pubkey_hex, _): +def test_get_pubkey(session: Session, pubkey_hex, _): response = nostr.get_pubkey( - client, + session, n=parse_path("m/44h/1237h/0h/0/0"), ) @@ -97,8 +98,8 @@ def test_get_pubkey(client, pubkey_hex, _): @pytest.mark.parametrize("pubkey_hex,expected_sig", VECTORS) -def test_sign_event(client, pubkey_hex, expected_sig): - response = nostr.sign_event(client, SIGN_TEST_EVENT) +def test_sign_event(session: Session, pubkey_hex, expected_sig): + response = nostr.sign_event(session, SIGN_TEST_EVENT) assert response.pubkey == bytes.fromhex(pubkey_hex)