refactor(core): rename `MsgInSignTx` to `HandlerChainIdArg`
What changed, and why it matters
This is a clean internal code rename in the Trezor firmware's Ethereum module. A shared type variable used by two different pieces of code is split into two separate type variables so that a future feature (EthereumSignAuth7702) can use the keychain helper without being incorrectly tied to transaction-signing code. No behavior changes, no bug fixes, and no security issue is present in the diff.
No security action needed. Treat as normal refactoring review.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors type variables in core/src/apps/ethereum/keychain.py. The existing MsgInSignTx TypeVar was used both by the with_keychain_from_chain_id decorator and by clearsigning helpers. The patch introduces a new HandlerChainIdArg TypeVar bound to EthereumSignAuth7702, EthereumSignTx, and EthereumSignTxEIP1559 for the decorator, while keeping MsgInSignTx bound only to EthereumSignTx and EthereumSignTxEIP1559 for (clear-)signing code. The decorator’s type annotations are updated accordingly, and a comment is adjusted. There are no runtime logic changes.
Changed components
core/src/apps/ethereum/keychain.pyInspect captured patch +17 / −8
diff --git a/core/src/apps/ethereum/keychain.py b/core/src/apps/ethereum/keychain.py
index c59cc157..8b5ddca1 100644
--- a/core/src/apps/ethereum/keychain.py
+++ b/core/src/apps/ethereum/keychain.py
@@ -12,6 +12,7 @@ if TYPE_CHECKING:
from trezor.messages import (
EthereumGetAddress,
+ EthereumSignAuth7702,
EthereumSignMessage,
EthereumSignTx,
EthereumSignTxEIP1559,
@@ -33,18 +34,26 @@ if TYPE_CHECKING:
Awaitable[MsgOut],
]
- # messages for "with_keychain_and_defs_from_chain_id" decorator
- MsgInSignTx = TypeVar(
- "MsgInSignTx",
+ # messages for "with_keychain_from_chain_id" decorator
+ HandlerChainIdArg = TypeVar(
+ "HandlerChainIdArg",
+ EthereumSignAuth7702,
EthereumSignTx,
EthereumSignTxEIP1559,
)
HandlerChainId = Callable[
- [MsgInSignTx, Keychain, definitions.Definitions],
+ [HandlerChainIdArg, Keychain, definitions.Definitions],
Awaitable[MsgOut],
]
+ # messages used for (clear-)signing transactions
+ MsgInSignTx = TypeVar(
+ "MsgInSignTx",
+ EthereumSignTx,
+ EthereumSignTxEIP1559,
+ )
+
# We believe Ethereum should use 44'/60'/a' for everything, because it is
# account-based, rather than UTXO-based. Unfortunately, lot of Ethereum
@@ -135,10 +144,10 @@ def with_keychain_from_path(
def with_keychain_from_chain_id(
- func: HandlerChainId[MsgInSignTx, MsgOut],
-) -> Handler[MsgInSignTx, MsgOut]:
- # this is only for SignTx, and only PATTERN_ADDRESS is allowed
- async def wrapper(msg: MsgInSignTx) -> MsgOut:
+ func: HandlerChainId[HandlerChainIdArg, MsgOut],
+) -> Handler[HandlerChainIdArg, MsgOut]:
+ # this is only for SignTx & SignAuth7702, and only PATTERN_ADDRESS is allowed
+ async def wrapper(msg: HandlerChainIdArg) -> MsgOut:
defs = _defs_from_message(msg, chain_id=msg.chain_id)
schemas = _schemas_from_network(PATTERNS_ADDRESS, defs.network)
keychain = await get_keychain(CURVE, schemas, [[b"SLIP-0024"]])
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.