mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-19 14:08:11 +00:00
refactor(core): use set-/get_bool in storage cache
[no changelog]
This commit is contained in:
parent
108d9c737e
commit
7a32ebf2b6
@ -203,7 +203,7 @@ async def handle_Initialize(msg: Initialize) -> Features:
|
||||
session_id = storage_cache.start_session(msg.session_id)
|
||||
|
||||
if not utils.BITCOIN_ONLY:
|
||||
derive_cardano = storage_cache.get(storage_cache.APP_COMMON_DERIVE_CARDANO)
|
||||
derive_cardano = storage_cache.get_bool(storage_cache.APP_COMMON_DERIVE_CARDANO)
|
||||
have_seed = storage_cache.is_set(storage_cache.APP_COMMON_SEED)
|
||||
|
||||
if (
|
||||
@ -218,9 +218,8 @@ async def handle_Initialize(msg: Initialize) -> Features:
|
||||
have_seed = False
|
||||
|
||||
if not have_seed:
|
||||
storage_cache.set(
|
||||
storage_cache.APP_COMMON_DERIVE_CARDANO,
|
||||
b"\x01" if msg.derive_cardano else b"",
|
||||
storage_cache.set_bool(
|
||||
storage_cache.APP_COMMON_DERIVE_CARDANO, bool(msg.derive_cardano)
|
||||
)
|
||||
|
||||
features = get_features()
|
||||
|
@ -112,7 +112,7 @@ def is_minting_path(path: Bip32Path) -> bool:
|
||||
|
||||
def derive_and_store_secrets(passphrase: str) -> None:
|
||||
assert device.is_initialized()
|
||||
assert cache.get(cache.APP_COMMON_DERIVE_CARDANO)
|
||||
assert cache.get_bool(cache.APP_COMMON_DERIVE_CARDANO)
|
||||
|
||||
if not mnemonic.is_bip39():
|
||||
# nothing to do for SLIP-39, where we can derive the root from the main seed
|
||||
@ -148,7 +148,7 @@ async def _get_keychain_bip39(derivation_type: CardanoDerivationType) -> Keychai
|
||||
seed = await get_seed()
|
||||
return Keychain(cardano.from_seed_ledger(seed))
|
||||
|
||||
if not cache.get(cache.APP_COMMON_DERIVE_CARDANO):
|
||||
if not cache.get_bool(cache.APP_COMMON_DERIVE_CARDANO):
|
||||
raise wire.ProcessError("Cardano derivation is not enabled for this session")
|
||||
|
||||
if derivation_type == CardanoDerivationType.ICARUS:
|
||||
|
@ -57,7 +57,7 @@ if not utils.BITCOIN_ONLY:
|
||||
raise wire.NotInitialized("Device is not initialized")
|
||||
|
||||
need_seed = not storage_cache.is_set(storage_cache.APP_COMMON_SEED)
|
||||
need_cardano_secret = storage_cache.get(
|
||||
need_cardano_secret = storage_cache.get_bool(
|
||||
storage_cache.APP_COMMON_DERIVE_CARDANO
|
||||
) and not storage_cache.is_set(storage_cache.APP_CARDANO_ICARUS_SECRET)
|
||||
|
||||
|
@ -64,9 +64,9 @@ async def _init_step(
|
||||
|
||||
await paths.validate_path(keychain, msg.address_n)
|
||||
|
||||
if not storage_cache.get(storage_cache.APP_MONERO_LIVE_REFRESH):
|
||||
if not storage_cache.get_bool(storage_cache.APP_MONERO_LIVE_REFRESH):
|
||||
await layout.require_confirm_live_refresh()
|
||||
storage_cache.set(storage_cache.APP_MONERO_LIVE_REFRESH, b"\x01")
|
||||
storage_cache.set_bool(storage_cache.APP_MONERO_LIVE_REFRESH, True)
|
||||
|
||||
s.creds = misc.get_creds(keychain, msg.address_n, msg.network_type)
|
||||
|
||||
|
@ -112,10 +112,10 @@ class SessionCache(DataCache):
|
||||
2, # APP_COMMON_AUTHORIZATION_TYPE
|
||||
128, # APP_COMMON_AUTHORIZATION_DATA
|
||||
32, # APP_COMMON_NONCE
|
||||
1, # APP_COMMON_DERIVE_CARDANO
|
||||
0, # APP_COMMON_DERIVE_CARDANO
|
||||
96, # APP_CARDANO_ICARUS_SECRET
|
||||
96, # APP_CARDANO_ICARUS_TREZOR_SECRET
|
||||
1, # APP_MONERO_LIVE_REFRESH
|
||||
0, # APP_MONERO_LIVE_REFRESH
|
||||
)
|
||||
self.last_usage = 0
|
||||
super().__init__()
|
||||
|
@ -31,11 +31,11 @@ def delete(
|
||||
config.delete(app, key, public, writable_locked)
|
||||
|
||||
|
||||
def set_true_or_delete(app: int, key: int, value: bool) -> None:
|
||||
def set_true_or_delete(app: int, key: int, value: bool, public: bool = False) -> None:
|
||||
if value:
|
||||
set_bool(app, key, value)
|
||||
set_bool(app, key, value, public)
|
||||
else:
|
||||
delete(app, key)
|
||||
delete(app, key, public)
|
||||
|
||||
|
||||
def set_bool(app: int, key: int, value: bool, public: bool = False) -> None:
|
||||
|
Loading…
Reference in New Issue
Block a user