1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-01 20:08:26 +00:00
This commit is contained in:
M1nd3r 2024-11-22 20:24:19 +01:00
parent 9927f74338
commit 0696fd5435
2 changed files with 17 additions and 4 deletions

View File

@ -94,6 +94,7 @@ class Session:
class SessionV1(Session): class SessionV1(Session):
derive_cardano: bool = False
@classmethod @classmethod
def new( def new(
cls, client: TrezorClient, passphrase: str = "", derive_cardano: bool = False cls, client: TrezorClient, passphrase: str = "", derive_cardano: bool = False
@ -109,7 +110,8 @@ class SessionV1(Session):
session.pin_callback = client.pin_callback session.pin_callback = client.pin_callback
session.passphrase_callback = _callback_passphrase session.passphrase_callback = _callback_passphrase
session.passphrase = passphrase session.passphrase = passphrase
session._init_session(derive_cardano=derive_cardano) session.derive_cardano = derive_cardano
session._init_session()
return session return session
def _write(self, msg: t.Any) -> None: def _write(self, msg: t.Any) -> None:
@ -122,10 +124,18 @@ class SessionV1(Session):
assert isinstance(self.client.protocol, ProtocolV1) assert isinstance(self.client.protocol, ProtocolV1)
return self.client.protocol.read() return self.client.protocol.read()
def _init_session(self, derive_cardano: bool = False): def _init_session(self):
self.call_raw( if self.id == b"":
messages.Initialize(session_id=self.id, derive_cardano=derive_cardano) 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: def _callback_button(session: Session, msg: t.Any) -> t.Any:
print("Please confirm action on your Trezor device.") # TODO how to handle UI? print("Please confirm action on your Trezor device.") # TODO how to handle UI?

View File

@ -794,6 +794,8 @@ def test_get_address(session: Session):
def test_multisession_authorization(client: Client): def test_multisession_authorization(client: Client):
# Authorize CoinJoin with www.example1.com in session 1. # Authorize CoinJoin with www.example1.com in session 1.
session1 = client.get_session() session1 = client.get_session()
session_id_1 = session1.id
btc.authorize_coinjoin( btc.authorize_coinjoin(
session1, session1,
coordinator="www.example1.com", coordinator="www.example1.com",
@ -805,6 +807,7 @@ def test_multisession_authorization(client: Client):
script_type=messages.InputScriptType.SPENDTAPROOT, script_type=messages.InputScriptType.SPENDTAPROOT,
) )
session2 = client.get_session() session2 = client.get_session()
session_id_2 = session2.id
# Open a second session. # Open a second session.
# session_id1 = session.session_id # session_id1 = session.session_id
# TODO client.init_device(new_session=True) # TODO client.init_device(new_session=True)