mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-01 11:58:28 +00:00
fix(core): update structure of common seed so it works on BTC_ONLY
[no changelog]
This commit is contained in:
parent
74804177ca
commit
f671802da7
@ -68,66 +68,78 @@ if utils.USE_THP:
|
||||
assert common_seed is not None
|
||||
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 get_seed() -> bytes:
|
||||
await derive_and_store_roots_legacy()
|
||||
common_seed = context.cache_get(APP_COMMON_SEED)
|
||||
assert common_seed is not None
|
||||
return common_seed
|
||||
async def derive_and_store_roots(
|
||||
ctx: Context, msg: ThpCreateNewSession
|
||||
) -> None:
|
||||
|
||||
if msg.passphrase is not None and msg.on_device:
|
||||
raise DataError("Passphrase provided when it shouldn't be!")
|
||||
|
||||
if utils.BITCOIN_ONLY:
|
||||
# === Bitcoin_only variant ===
|
||||
# We want to derive the normal seed ONLY
|
||||
if ctx.cache.is_set(APP_COMMON_SEED):
|
||||
raise Exception("Seed is already set!")
|
||||
|
||||
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:
|
||||
raise DataError("Passphrase provided when it shouldn't be!")
|
||||
if not storage_device.is_initialized():
|
||||
raise wire.NotInitialized("Device is not initialized")
|
||||
|
||||
if ctx.cache.is_set(APP_COMMON_SEED):
|
||||
raise Exception("Seed is already set!")
|
||||
passphrase = await get_passphrase(msg)
|
||||
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():
|
||||
raise wire.NotInitialized("Device is not initialized")
|
||||
if msg.passphrase is not None and msg.on_device:
|
||||
raise DataError("Passphrase provided when it shouldn't be!")
|
||||
|
||||
passphrase = await get_passphrase(msg)
|
||||
common_seed = mnemonic.get_seed(passphrase)
|
||||
ctx.cache.set(APP_COMMON_SEED, common_seed)
|
||||
from trezor import wire
|
||||
|
||||
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:
|
||||
# === 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
|
||||
if utils.BITCOIN_ONLY:
|
||||
# === Bitcoin-only variant ===
|
||||
# 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:
|
||||
raise DataError("Passphrase provided when it shouldn't be!")
|
||||
else:
|
||||
# === 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
|
||||
|
||||
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)
|
||||
|
||||
if not utils.USE_THP:
|
||||
@cache.stored_async(APP_COMMON_SEED)
|
||||
async def get_seed() -> bytes:
|
||||
await derive_and_store_roots_legacy()
|
||||
common_seed = context.cache_get(APP_COMMON_SEED)
|
||||
assert common_seed is not None
|
||||
return common_seed
|
||||
|
||||
async def derive_and_store_roots_legacy() -> None:
|
||||
from trezor import wire
|
||||
|
Loading…
Reference in New Issue
Block a user