From 0696fd5435eb6a14aef44e251e08746ea213705d Mon Sep 17 00:00:00 2001 From: M1nd3r Date: Fri, 22 Nov 2024 20:24:19 +0100 Subject: [PATCH] wip --- python/src/trezorlib/transport/session.py | 18 ++++++++++++++---- .../bitcoin/test_authorize_coinjoin.py | 3 +++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/python/src/trezorlib/transport/session.py b/python/src/trezorlib/transport/session.py index a5d8ada5e4..98866b2564 100644 --- a/python/src/trezorlib/transport/session.py +++ b/python/src/trezorlib/transport/session.py @@ -94,6 +94,7 @@ class Session: class SessionV1(Session): + derive_cardano: bool = False @classmethod def new( cls, client: TrezorClient, passphrase: str = "", derive_cardano: bool = False @@ -109,7 +110,8 @@ class SessionV1(Session): session.pin_callback = client.pin_callback session.passphrase_callback = _callback_passphrase session.passphrase = passphrase - session._init_session(derive_cardano=derive_cardano) + session.derive_cardano = derive_cardano + session._init_session() return session def _write(self, msg: t.Any) -> None: @@ -122,10 +124,18 @@ class SessionV1(Session): assert isinstance(self.client.protocol, ProtocolV1) return self.client.protocol.read() - def _init_session(self, derive_cardano: bool = False): - self.call_raw( - messages.Initialize(session_id=self.id, derive_cardano=derive_cardano) + def _init_session(self): + if self.id == b"": + session_id = None + else: + session_id = self.id + resp: messages.Features = self.call_raw( + messages.Initialize( + session_id=session_id, derive_cardano=self.derive_cardano + ) ) + self._id = resp.session_id + def _callback_button(session: Session, msg: t.Any) -> t.Any: print("Please confirm action on your Trezor device.") # TODO how to handle UI? diff --git a/tests/device_tests/bitcoin/test_authorize_coinjoin.py b/tests/device_tests/bitcoin/test_authorize_coinjoin.py index a90c7376af..be55b058a7 100644 --- a/tests/device_tests/bitcoin/test_authorize_coinjoin.py +++ b/tests/device_tests/bitcoin/test_authorize_coinjoin.py @@ -794,6 +794,8 @@ def test_get_address(session: Session): def test_multisession_authorization(client: Client): # Authorize CoinJoin with www.example1.com in session 1. session1 = client.get_session() + session_id_1 = session1.id + btc.authorize_coinjoin( session1, coordinator="www.example1.com", @@ -805,6 +807,7 @@ def test_multisession_authorization(client: Client): script_type=messages.InputScriptType.SPENDTAPROOT, ) session2 = client.get_session() + session_id_2 = session2.id # Open a second session. # session_id1 = session.session_id # TODO client.init_device(new_session=True)