mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-27 01:48:17 +00:00
src/apps/common: rewrite cache to use getters/setters
This commit is contained in:
parent
6fad2f4283
commit
c1e1e8bf02
@ -1,18 +1,25 @@
|
||||
seed = None
|
||||
_seed, _state = None, None
|
||||
|
||||
|
||||
def get_state():
|
||||
global seed
|
||||
if seed is None:
|
||||
return None
|
||||
else:
|
||||
from trezor.crypto import bip32
|
||||
from trezor.crypto.hashlib import blake2s
|
||||
node = bip32.from_seed(seed, 'secp256k1')
|
||||
state = blake2s(node.public_key()).digest()
|
||||
return state
|
||||
global _state
|
||||
return _state
|
||||
|
||||
|
||||
def get_seed():
|
||||
global _seed
|
||||
return _seed
|
||||
|
||||
|
||||
def set_seed(seed):
|
||||
from trezor.crypto import bip32
|
||||
from trezor.crypto.hashlib import blake2s
|
||||
node = bip32.from_seed(seed, 'secp256k1')
|
||||
state = blake2s(node.public_key()).digest()
|
||||
global _seed, _state
|
||||
_seed, _state = seed, state
|
||||
|
||||
|
||||
def clear():
|
||||
global seed
|
||||
seed = None
|
||||
global _seed, _state
|
||||
_seed, _state = None
|
||||
|
@ -15,9 +15,10 @@ async def derive_node(ctx: wire.Context, path=[], curve_name=_DEFAULT_CURVE):
|
||||
|
||||
async def _get_seed(ctx: wire.Context) -> bytes:
|
||||
from . import cache
|
||||
if cache.seed is None:
|
||||
cache.seed = await _compute_seed(ctx)
|
||||
return cache.seed
|
||||
if cache.get_seed() is None:
|
||||
seed = await _compute_seed(ctx)
|
||||
cache.set_seed(seed)
|
||||
return cache.get_seed()
|
||||
|
||||
|
||||
async def _compute_seed(ctx: wire.Context) -> bytes:
|
||||
|
@ -10,7 +10,7 @@ async def respond_Features(ctx, msg):
|
||||
from trezor.messages.Features import Features
|
||||
|
||||
if msg.__qualname__ == 'Initialize':
|
||||
if not hasattr(msg, 'state') or msg.state != cache.get_state():
|
||||
if msg.state is None or msg.state != cache.get_state():
|
||||
cache.clear()
|
||||
|
||||
f = Features()
|
||||
|
Loading…
Reference in New Issue
Block a user