feat(core): allow waiting for N4W1 emulator "connection"
What changed, and why it matters
This commit changes a debug-only mock file for the N4W1 hardware feature in Trezor firmware. It adds a user-facing 'hold the tag' screen that waits for a simulated tap/connection event before continuing. The change is confined to a debugging helper and does not appear to alter normal wallet security logic.
Treat as low-priority code-quality/debug-feature review. Verify that `confirm_connect()` is only invoked from debug flows and that the `assert res.value is None` cannot be triggered by malformed debug messages in production builds. No urgent security action is indicated.
Security signals we found
Debug-only code path (apps.debug namespace)
Adds assert on received response value
Introduces user-facing blocking layout with cancellation
No changelog entry supplied by author
Evidence from the diff
The patch modifies core/src/apps/debug/n4w1_mock.py, a debug-only mock for the N4W1 (NFC) interface. It adds a connect() coroutine that waits on an rx queue, injects an initial DebugLinkN4W1Response(value=None) into that queue inside handle(), and introduces a confirm_connect() method that displays an info layout and blocks until the mock reports a connection. The layout uses confirm_with_menu with an external menu and a cancellation option. The commit message explicitly frames this as emulator/connection waiting behavior and notes that actual data read/write will be handled separately.
Changed components
core/src/apps/debug/n4w1_mock.pyInspect captured patch +49 / −1
diff --git a/core/src/apps/debug/n4w1_mock.py b/core/src/apps/debug/n4w1_mock.py
index 842b9b65..8e4a56f4 100644
--- a/core/src/apps/debug/n4w1_mock.py
+++ b/core/src/apps/debug/n4w1_mock.py
@@ -2,10 +2,11 @@ from typing import TYPE_CHECKING
from trezor import log, loop
from trezor.messages import DebugLinkN4W1Read, DebugLinkN4W1Response, DebugLinkN4W1Write
+from trezor.ui import Layout
if TYPE_CHECKING:
from buffer_types import AnyBytes
- from typing import Any
+ from typing import Any, Awaitable, Iterator
from trezor.wire.context import Context
from typing_extensions import Self
@@ -28,6 +29,11 @@ class N4W1Context:
log.debug(__name__, "N4W1 exchange done")
self.tx.put(None)
+ async def connect(self) -> None:
+ """Wait for N4W1 connection notification."""
+ res = await self.rx
+ assert res.value is None
+
async def read(self, key: str) -> AnyBytes | None:
"""Read a specific entry from N4W1."""
log.debug(__name__, "N4W1 read: %s", key)
@@ -50,9 +56,51 @@ class N4W1Context:
async def handle(self, ctx: Context) -> None:
"""Called from `apps.debug.dispatch_DebugLinkConnected()`."""
+ self.rx.put(DebugLinkN4W1Response(value=None)) # notify `self.connect()`
while (req := await self.tx) is not None:
res = await ctx.call(req, DebugLinkN4W1Response)
self.rx.put(res)
+ def confirm_connect(
+ self, *, title: str, description: str, button: str, br_name: str | None
+ ) -> Awaitable[None]:
+ """Show a layout waiting for N4W1 connection, allowing cancellation."""
+
+ from trezor import TR
+ from trezor.ui.layouts.menu import Menu, confirm_with_menu
+ from trezorui_api import show_info
+
+ self_ctx: N4W1Context = self
+
+ class _Connect(Layout):
+
+ def create_tasks(self) -> Iterator[loop.Task[None]]:
+ from trezor.ui import Shutdown
+ from trezorui_api import CONFIRMED
+
+ async def _task() -> None:
+ await self_ctx.connect() # blocks until N4W1 is connected.
+ try:
+ # emitting a message raises Shutdown exception
+ self._emit_message(CONFIRMED)
+ except Shutdown:
+ pass
+
+ yield from super().create_tasks()
+ yield _task()
+
+ main = show_info(
+ title=title,
+ description=description,
+ button=(button, False),
+ external_menu=True,
+ )
+ return confirm_with_menu(
+ main,
+ Menu.root(cancel=TR.buttons__cancel),
+ br_name=br_name,
+ layout_type=_Connect,
+ )
+
ctx = N4W1Context()
Why this scored 21/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.