1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-07 14:00:57 +00:00

fix(core): update structure of common seed so it works on BTC_ONLY

[no changelog]
This commit is contained in:
M1nd3r 2024-11-27 12:21:35 +01:00
parent c89106656f
commit 2b51be1eab

View File

@ -68,66 +68,78 @@ if utils.USE_THP:
assert common_seed is not None assert common_seed is not None
return common_seed return common_seed
else: if utils.BITCOIN_ONLY:
# === Bitcoin_only variant ===
# We want to derive the normal seed ONLY
@cache.stored_async(APP_COMMON_SEED) async def derive_and_store_roots(
async def get_seed() -> bytes: ctx: Context, msg: ThpCreateNewSession
await derive_and_store_roots_legacy() ) -> None:
common_seed = context.cache_get(APP_COMMON_SEED)
assert common_seed is not None
return common_seed
if msg.passphrase is not None and msg.on_device:
raise DataError("Passphrase provided when it shouldn't be!")
if utils.BITCOIN_ONLY: if ctx.cache.is_set(APP_COMMON_SEED):
# === Bitcoin_only variant === raise Exception("Seed is already set!")
# We want to derive the normal seed ONLY
async def derive_and_store_roots(ctx: Context, msg: ThpCreateNewSession) -> None: from trezor import wire
if msg.passphrase is not None and msg.on_device: if not storage_device.is_initialized():
raise DataError("Passphrase provided when it shouldn't be!") raise wire.NotInitialized("Device is not initialized")
if ctx.cache.is_set(APP_COMMON_SEED): passphrase = await get_passphrase(msg)
raise Exception("Seed is already set!") common_seed = mnemonic.get_seed(passphrase)
ctx.cache.set(APP_COMMON_SEED, common_seed)
from trezor import wire else:
# === Cardano variant ===
# We want to derive both the normal seed and the Cardano seed together
async def derive_and_store_roots(
ctx: Context, msg: ThpCreateNewSession
) -> None:
if not storage_device.is_initialized(): if msg.passphrase is not None and msg.on_device:
raise wire.NotInitialized("Device is not initialized") raise DataError("Passphrase provided when it shouldn't be!")
passphrase = await get_passphrase(msg) from trezor import wire
common_seed = mnemonic.get_seed(passphrase)
ctx.cache.set(APP_COMMON_SEED, common_seed) if not storage_device.is_initialized():
raise wire.NotInitialized("Device is not initialized")
if ctx.cache.is_set(APP_CARDANO_ICARUS_SECRET):
raise Exception("Cardano icarus secret is already set!")
passphrase = await get_passphrase(msg)
common_seed = mnemonic.get_seed(passphrase)
ctx.cache.set(APP_COMMON_SEED, common_seed)
if msg.derive_cardano:
from apps.cardano.seed import derive_and_store_secrets
ctx.cache.set_bool(APP_COMMON_DERIVE_CARDANO, True)
derive_and_store_secrets(ctx, passphrase)
else: else:
# === Cardano variant === if utils.BITCOIN_ONLY:
# We want to derive both the normal seed and the Cardano seed together, AND # === Bitcoin-only variant ===
# expose a method for Cardano to do the same # We use the simple version of `get_seed` that never needs to derive anything else.
async def derive_and_store_roots(ctx: Context, msg: ThpCreateNewSession) -> None: @cache.stored_async(APP_COMMON_SEED)
async def get_seed() -> bytes:
passphrase = await get_passphrase_legacy()
return mnemonic.get_seed(passphrase=passphrase)
if msg.passphrase is not None and msg.on_device: else:
raise DataError("Passphrase provided when it shouldn't be!") # === Cardano variant ===
# We want to derive both the normal seed and the Cardano seed together, AND
# expose a method for Cardano to do the same
from trezor import wire @cache.stored_async(APP_COMMON_SEED)
async def get_seed() -> bytes:
if not storage_device.is_initialized(): await derive_and_store_roots_legacy()
raise wire.NotInitialized("Device is not initialized") common_seed = context.cache_get(APP_COMMON_SEED)
assert common_seed is not None
if ctx.cache.is_set(APP_CARDANO_ICARUS_SECRET): return common_seed
raise Exception("Cardano icarus secret is already set!")
passphrase = await get_passphrase(msg)
common_seed = mnemonic.get_seed(passphrase)
ctx.cache.set(APP_COMMON_SEED, common_seed)
if msg.derive_cardano:
from apps.cardano.seed import derive_and_store_secrets
ctx.cache.set_bool(APP_COMMON_DERIVE_CARDANO, True)
derive_and_store_secrets(ctx, passphrase)
if not utils.USE_THP:
async def derive_and_store_roots_legacy() -> None: async def derive_and_store_roots_legacy() -> None:
from trezor import wire from trezor import wire