mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 15:38:11 +00:00
core: cache seed without passphrase (#478)
This commit is contained in:
parent
41b76f4f31
commit
c1f0c642df
@ -6,6 +6,7 @@ if False:
|
||||
from typing import Optional
|
||||
|
||||
_cached_seed = None # type: Optional[bytes]
|
||||
_cached_seed_without_passphrase = None # type: Optional[bytes]
|
||||
_cached_passphrase = None # type: Optional[str]
|
||||
_cached_passphrase_fprint = b"\x00\x00\x00\x00" # type: bytes
|
||||
|
||||
@ -36,6 +37,10 @@ def get_seed() -> Optional[bytes]:
|
||||
return _cached_seed
|
||||
|
||||
|
||||
def get_seed_without_passphrase() -> Optional[bytes]:
|
||||
return _cached_seed_without_passphrase
|
||||
|
||||
|
||||
def get_passphrase() -> Optional[str]:
|
||||
return _cached_passphrase
|
||||
|
||||
@ -53,6 +58,11 @@ def set_seed(seed: Optional[bytes]) -> None:
|
||||
_cached_seed = seed
|
||||
|
||||
|
||||
def set_seed_without_passphrase(seed: Optional[bytes]) -> None:
|
||||
global _cached_seed_without_passphrase
|
||||
_cached_seed_without_passphrase = seed
|
||||
|
||||
|
||||
def set_passphrase(passphrase: Optional[str]) -> None:
|
||||
global _cached_passphrase, _cached_passphrase_fprint
|
||||
_cached_passphrase = passphrase
|
||||
@ -61,5 +71,6 @@ def set_passphrase(passphrase: Optional[str]) -> None:
|
||||
|
||||
def clear(keep_passphrase: bool = False) -> None:
|
||||
set_seed(None)
|
||||
set_seed_without_passphrase(None)
|
||||
if not keep_passphrase:
|
||||
set_passphrase(None)
|
||||
|
@ -126,7 +126,10 @@ def derive_node_without_passphrase(
|
||||
) -> bip32.HDNode:
|
||||
if not storage.is_initialized():
|
||||
raise Exception("Device is not initialized")
|
||||
seed = mnemonic.get_seed(progress_bar=False)
|
||||
seed = cache.get_seed_without_passphrase()
|
||||
if seed is None:
|
||||
seed = mnemonic.get_seed(progress_bar=False)
|
||||
cache.set_seed_without_passphrase(seed)
|
||||
node = bip32.from_seed(seed, curve_name)
|
||||
node.derive_path(path)
|
||||
return node
|
||||
@ -135,7 +138,10 @@ def derive_node_without_passphrase(
|
||||
def derive_slip21_node_without_passphrase(path: list) -> Slip21Node:
|
||||
if not storage.is_initialized():
|
||||
raise Exception("Device is not initialized")
|
||||
seed = mnemonic.get_seed(progress_bar=False)
|
||||
seed = cache.get_seed_without_passphrase()
|
||||
if seed is None:
|
||||
seed = mnemonic.get_seed(progress_bar=False)
|
||||
cache.set_seed_without_passphrase(seed)
|
||||
node = Slip21Node(seed)
|
||||
node.derive_path(path)
|
||||
return node
|
||||
|
Loading…
Reference in New Issue
Block a user