1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-17 05:03:07 +00:00

feat(core/cardano): indicate whether Cardano seed should be derived

This commit is contained in:
matejcik 2021-10-12 13:58:23 +02:00 committed by matejcik
parent 80e4b27f09
commit 8caac218ec
5 changed files with 40 additions and 9 deletions

View File

@ -33,7 +33,10 @@ enum SafetyCheckLevel {
* @next Features
*/
message Initialize {
optional bytes session_id = 1; // assumed device session id; Trezor clears caches if it is different or empty
optional bytes session_id = 1; // assumed device session id; Trezor clears caches if it is different or empty
// optional bool skip_passphrase = 2; // removed as part of passphrase redesign
reserved 2;
optional bool derive_cardano = 3; // whether to derive Cardano Icarus root keys in this session
}
/**

View File

@ -98,10 +98,31 @@ def get_features() -> Features:
async def handle_Initialize(ctx: wire.Context, 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)
have_seed = storage.cache.is_set(storage.cache.APP_COMMON_SEED)
if (
have_seed
and msg.derive_cardano is not None
and msg.derive_cardano != bool(derive_cardano)
):
# seed is already derived, and host wants to change derive_cardano setting
# => create a new session
storage.cache.end_current_session()
session_id = storage.cache.start_session()
have_seed = False
if not have_seed:
storage.cache.set(
storage.cache.APP_COMMON_DERIVE_CARDANO,
b"\x01" if msg.derive_cardano else b"",
)
features = get_features()
if msg.session_id:
msg.session_id = bytes(msg.session_id)
features.session_id = storage.cache.start_session(msg.session_id)
features.session_id = session_id
return features

View File

@ -20,10 +20,11 @@ _SESSION_ID_LENGTH = 32
# Traditional cache keys
APP_COMMON_SEED = 0
APP_CARDANO_PASSPHRASE = 1
APP_MONERO_LIVE_REFRESH = 2
APP_COMMON_AUTHORIZATION_TYPE = 3
APP_COMMON_AUTHORIZATION_DATA = 4
APP_COMMON_DERIVE_CARDANO = 1
APP_CARDANO_XPRV = 2
APP_MONERO_LIVE_REFRESH = 3
APP_COMMON_AUTHORIZATION_TYPE = 4
APP_COMMON_AUTHORIZATION_DATA = 5
# Keys that are valid across sessions
APP_COMMON_SEED_WITHOUT_PASSPHRASE = 0 | _SESSIONLESS_FLAG
@ -87,7 +88,8 @@ class SessionCache(DataCache):
self.session_id = bytearray(_SESSION_ID_LENGTH)
self.fields = (
64, # APP_COMMON_SEED
50, # APP_CARDANO_PASSPHRASE
1, # APP_COMMON_DERIVE_CARDANO
96, # APP_CARDANO_XPRV
1, # APP_MONERO_LIVE_REFRESH
2, # APP_COMMON_AUTHORIZATION_TYPE
128, # APP_COMMON_AUTHORIZATION_DATA

View File

@ -1784,11 +1784,13 @@ if TYPE_CHECKING:
class Initialize(protobuf.MessageType):
session_id: "bytes | None"
derive_cardano: "bool | None"
def __init__(
self,
*,
session_id: "bytes | None" = None,
derive_cardano: "bool | None" = None,
) -> None:
pass

View File

@ -2986,14 +2986,17 @@ class Initialize(protobuf.MessageType):
MESSAGE_WIRE_TYPE = 0
FIELDS = {
1: protobuf.Field("session_id", "bytes", repeated=False, required=False),
3: protobuf.Field("derive_cardano", "bool", repeated=False, required=False),
}
def __init__(
self,
*,
session_id: Optional["bytes"] = None,
derive_cardano: Optional["bool"] = None,
) -> None:
self.session_id = session_id
self.derive_cardano = derive_cardano
class GetFeatures(protobuf.MessageType):