mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-01 20:32:35 +00:00

Changes many fields to required -- as far as we were able to figure out, signing would fail if these fields aren't provided anyway, so this should not pose a compatibility problem. Co-authored-by: matejcik <ja@matejcik.cz>
53 lines
1.8 KiB
Python
53 lines
1.8 KiB
Python
from typing import Iterable
|
|
|
|
import storage.cache
|
|
from trezor import protobuf
|
|
from trezor.enums import MessageType
|
|
from trezor.utils import ensure
|
|
|
|
WIRE_TYPES: dict[int, tuple[int, ...]] = {
|
|
MessageType.AuthorizeCoinJoin: (MessageType.SignTx, MessageType.GetOwnershipProof),
|
|
}
|
|
|
|
|
|
def is_set() -> bool:
|
|
return bool(storage.cache.get(storage.cache.APP_COMMON_AUTHORIZATION_TYPE))
|
|
|
|
|
|
def set(auth_message: protobuf.MessageType) -> None:
|
|
buffer = protobuf.dump_message_buffer(auth_message)
|
|
|
|
# only wire-level messages can be stored as authorization
|
|
# (because only wire-level messages have wire_type, which we use as identifier)
|
|
ensure(auth_message.MESSAGE_WIRE_TYPE is not None)
|
|
assert auth_message.MESSAGE_WIRE_TYPE is not None # so that typechecker knows too
|
|
storage.cache.set(
|
|
storage.cache.APP_COMMON_AUTHORIZATION_TYPE,
|
|
auth_message.MESSAGE_WIRE_TYPE.to_bytes(2, "big"),
|
|
)
|
|
storage.cache.set(storage.cache.APP_COMMON_AUTHORIZATION_DATA, buffer)
|
|
|
|
|
|
def get() -> protobuf.MessageType | None:
|
|
stored_auth_type = storage.cache.get(storage.cache.APP_COMMON_AUTHORIZATION_TYPE)
|
|
if not stored_auth_type:
|
|
return None
|
|
|
|
msg_wire_type = int.from_bytes(stored_auth_type, "big")
|
|
buffer = storage.cache.get(storage.cache.APP_COMMON_AUTHORIZATION_DATA, b"")
|
|
return protobuf.load_message_buffer(buffer, msg_wire_type)
|
|
|
|
|
|
def get_wire_types() -> Iterable[int]:
|
|
stored_auth_type = storage.cache.get(storage.cache.APP_COMMON_AUTHORIZATION_TYPE)
|
|
if stored_auth_type is None:
|
|
return ()
|
|
|
|
msg_wire_type = int.from_bytes(stored_auth_type, "big")
|
|
return WIRE_TYPES.get(msg_wire_type, ())
|
|
|
|
|
|
def clear() -> None:
|
|
storage.cache.delete(storage.cache.APP_COMMON_AUTHORIZATION_TYPE)
|
|
storage.cache.delete(storage.cache.APP_COMMON_AUTHORIZATION_DATA)
|