2019-11-08 08:43:32 +00:00
|
|
|
from trezor.crypto import random
|
2018-07-03 14:20:26 +00:00
|
|
|
|
2019-07-03 13:07:04 +00:00
|
|
|
if False:
|
|
|
|
from typing import Optional
|
2018-02-24 17:58:02 +00:00
|
|
|
|
2019-07-03 13:07:04 +00:00
|
|
|
_cached_seed = None # type: Optional[bytes]
|
2019-11-08 08:43:32 +00:00
|
|
|
_cached_seed_without_passphrase = None # type: Optional[bytes] # Needed for SLIP-21
|
|
|
|
_cached_session_id = None # type: Optional[bytes]
|
2018-02-24 17:58:02 +00:00
|
|
|
|
2019-07-03 13:07:04 +00:00
|
|
|
|
2019-11-23 18:12:57 +00:00
|
|
|
def get_session_id() -> bytes:
|
2019-11-08 08:43:32 +00:00
|
|
|
global _cached_session_id
|
|
|
|
if not _cached_session_id:
|
|
|
|
_cached_session_id = random.bytes(32)
|
|
|
|
return _cached_session_id
|
2018-02-28 23:07:45 +00:00
|
|
|
|
2017-05-08 20:31:21 +00:00
|
|
|
|
2019-11-08 08:43:32 +00:00
|
|
|
def set_seed(seed: Optional[bytes]) -> None:
|
|
|
|
global _cached_seed
|
|
|
|
_cached_seed = seed
|
2018-02-09 17:59:26 +00:00
|
|
|
|
|
|
|
|
2019-07-03 13:07:04 +00:00
|
|
|
def get_seed() -> Optional[bytes]:
|
2018-05-28 13:20:31 +00:00
|
|
|
return _cached_seed
|
2018-02-09 17:59:26 +00:00
|
|
|
|
|
|
|
|
2019-09-02 10:09:03 +00:00
|
|
|
def set_seed_without_passphrase(seed: Optional[bytes]) -> None:
|
|
|
|
global _cached_seed_without_passphrase
|
|
|
|
_cached_seed_without_passphrase = seed
|
|
|
|
|
|
|
|
|
2019-11-08 08:43:32 +00:00
|
|
|
def get_seed_without_passphrase() -> Optional[bytes]:
|
|
|
|
return _cached_seed_without_passphrase
|
|
|
|
|
2018-05-28 13:20:31 +00:00
|
|
|
|
2019-11-08 08:43:32 +00:00
|
|
|
def clear() -> None:
|
|
|
|
global _cached_session_id
|
|
|
|
_cached_session_id = None
|
2018-05-28 13:20:31 +00:00
|
|
|
|
|
|
|
set_seed(None)
|
2019-09-02 10:09:03 +00:00
|
|
|
set_seed_without_passphrase(None)
|