Skip to content

feat(core): misc features add #286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 11, 2025
Merged

feat(core): misc features add #286

merged 1 commit into from
Apr 11, 2025

Conversation

somebodyLi
Copy link
Contributor

@somebodyLi somebodyLi commented Apr 11, 2025

  1. the passphrase input on device supports edit before commit.
  2. mnemonics support edits if make mistake in input process
  3. fingerprint unlock error tips in pin input screen

Summary by CodeRabbit

  • New Features

    • Enhanced passphrase and recovery screens with interactive mnemonic corrections and improved fingerprint/PIN prompts.
    • Introduced a new button style offering a clean, no-background appearance.
    • Updated network labeling for Neo addresses to reflect the latest version ("Neo N3").
  • Bug Fixes

    • Improved error handling during passphrase confirmation and recovery processes.
    • Optimized data processing for message signing and transaction handling for smoother performance.

1. the passphrase input on device supports edit before commit.
2. mnemonics support edits if make mistake in input process
3. fingerprint unlock error tips in pin input screen
@somebodyLi somebodyLi requested a review from a team as a code owner April 11, 2025 02:24
Copy link

coderabbitai bot commented Apr 11, 2025

Walkthrough

This pull request refactors control flows and updates function signatures. It introduces error handling for passphrase confirmation and adjusts mnemonic recovery logic with interactive word handling. The changes update network specifications for Neo to “Neo N3” and modify signature methods for SUI messages and transactions. UI components such as buttons, passphrase displays, and pin screens now have additional methods and refined state handling. LVGL layout functions and common sign/verify routines also receive updated type support and streamlined processing.

Changes

File(s) Change Summary
core/src/apps/common/passphrase.py
core/src/trezor/lvglui/scrs/passphrase.py
Added conditional passphrase confirmation with error raise and updated PassphraseRequest to accept an optional result parameter with renamed variables.
core/src/trezor/ui/layouts/lvgl/__init__.py Updated function signatures for confirm_data, request_passphrase_on_device, require_confirm_passphrase (added from_device), and confirm_blind_sign_common (accepts bytearray).
core/src/apps/management/recovery_device/homescreen.py
core/src/apps/management/recovery_device/layout.py
core/src/trezor/lvglui/scrs/recovery_device.py
Refined recovery process and mnemonic validation. Added interactive word handling via request_word, updated parameter type for show_invalid_mnemonic, and introduced an InvalidMnemonic class with updated type annotations.
core/src/apps/neo/get_address.py
core/src/apps/neo/helpers.py
core/src/trezor/lvglui/scrs/address.py
Changed network configuration from “Neo” to “Neo N3” in address display and network retrieval functions.
core/src/apps/sui/sign_message.py
core/src/apps/sui/sign_tx.py
Revised SUI signing by replacing concatenation with sequential blake2b.update calls and altered data appending to use extend(), with added garbage collection call in transaction chunks.
core/src/trezor/lvglui/scrs/components/button.py
core/src/trezor/lvglui/scrs/pinscreen.py
Introduced enable_no_bg_mode for buttons and enhanced InputPin subtitle handling with new methods change_subtitle, show_fp_failed_prompt, and anim_set_x.
core/src/trezor/lvglui/scrs/template.py Updated PassphraseDisplayConfirm to include a from_device parameter with conditional cancel text and added a warning banner; modified the Message class to adjust full message display parameters.
core/src/trezor/uart.py Added conditional logic in fingerprint handling to check InputPin visibility and trigger a fingerprint failure prompt accordingly.
core/src/apps/common/signverify.py Introduced a local to_hex function in decode_message, updated message decoding, and improved error handling with garbage collection in case of UnicodeError.

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (3)
core/src/trezor/lvglui/scrs/recovery_device.py (1)

111-115: Comment doesn't match code.

Comment says "3 columns" but code defines 2 columns.

- # 3 columns
+ # 2 columns
core/src/trezor/lvglui/scrs/pinscreen.py (1)

259-263: Empty exception handler should use contextlib.suppress.

Use contextlib.suppress for cleaner exception handling:

-def anim_set_x(self, val):
-    try:
-        self.fingerprint_prompt.set_x(val)
-    except Exception:
-        pass
+def anim_set_x(self, val):
+    from contextlib import suppress
+    with suppress(Exception):
+        self.fingerprint_prompt.set_x(val)
🧰 Tools
🪛 Ruff (0.8.2)

260-263: Use contextlib.suppress(Exception) instead of try-except-pass

Replace with contextlib.suppress(Exception)

(SIM105)

core/src/trezor/ui/layouts/lvgl/__init__.py (1)

1142-1148: Missing return type hint for boolean return

Function now returns a boolean but lacks return type annotation.

-async def require_confirm_passphrase(
-    ctx: wire.GenericContext, passphrase: str, from_device: bool = False
-) -> bool:
+async def require_confirm_passphrase(
+    ctx: wire.GenericContext, passphrase: str, from_device: bool = False
+) -> bool:
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 29edc69 and 91431eb.

📒 Files selected for processing (16)
  • core/src/apps/common/passphrase.py (1 hunks)
  • core/src/apps/common/signverify.py (2 hunks)
  • core/src/apps/management/recovery_device/homescreen.py (3 hunks)
  • core/src/apps/management/recovery_device/layout.py (1 hunks)
  • core/src/apps/neo/get_address.py (1 hunks)
  • core/src/apps/neo/helpers.py (1 hunks)
  • core/src/apps/sui/sign_message.py (1 hunks)
  • core/src/apps/sui/sign_tx.py (4 hunks)
  • core/src/trezor/lvglui/scrs/address.py (1 hunks)
  • core/src/trezor/lvglui/scrs/components/button.py (1 hunks)
  • core/src/trezor/lvglui/scrs/passphrase.py (3 hunks)
  • core/src/trezor/lvglui/scrs/pinscreen.py (3 hunks)
  • core/src/trezor/lvglui/scrs/recovery_device.py (2 hunks)
  • core/src/trezor/lvglui/scrs/template.py (4 hunks)
  • core/src/trezor/uart.py (1 hunks)
  • core/src/trezor/ui/layouts/lvgl/__init__.py (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (5)
core/src/trezor/lvglui/scrs/components/button.py (1)
core/src/trezor/lvglui/lv_colors.py (1)
  • lv_colors (9-68)
core/src/apps/sui/sign_tx.py (2)
core/src/trezor/utils.py (4)
  • extend (473-474)
  • extend (486-487)
  • extend (533-534)
  • digest (460-461)
core/src/trezor/ui/layouts/lvgl/__init__.py (1)
  • confirm_blind_sign_common (1481-1499)
core/src/apps/management/recovery_device/homescreen.py (2)
core/src/trezor/ui/layouts/lvgl/recovery.py (1)
  • request_word (31-42)
core/src/apps/management/recovery_device/layout.py (2)
  • request_mnemonic (64-103)
  • show_invalid_mnemonic (156-166)
core/src/trezor/lvglui/scrs/recovery_device.py (4)
core/src/trezor/utils.py (1)
  • lcd_resume (167-196)
core/src/trezor/lvglui/scrs/common.py (1)
  • FullSizeWindow (360-639)
core/src/trezor/lvglui/scrs/components/button.py (2)
  • NormalButton (14-80)
  • enable_no_bg_mode (73-80)
core/src/trezor/lvglui/scrs/components/container.py (1)
  • ContainerGrid (114-146)
core/src/trezor/ui/layouts/lvgl/__init__.py (3)
core/src/trezor/enums/__init__.py (1)
  • ButtonRequestType (462-482)
core/src/trezor/lvglui/scrs/template.py (1)
  • PassphraseDisplayConfirm (2398-2451)
core/src/trezor/lvglui/scrs/passphrase.py (1)
  • PassphraseRequest (8-47)
🪛 Ruff (0.8.2)
core/src/trezor/lvglui/scrs/pinscreen.py

260-263: Use contextlib.suppress(Exception) instead of try-except-pass

Replace with contextlib.suppress(Exception)

(SIM105)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Gen check
  • GitHub Check: Style check
  • GitHub Check: Defs check
🔇 Additional comments (43)
core/src/trezor/lvglui/scrs/address.py (1)

321-321: LGTM: Network name updated to "Neo N3"

The network name change maintains consistency with other files.

core/src/apps/neo/helpers.py (1)

48-48: LGTM: Network name updated to "Neo N3"

The return value change is consistent with the codebase updates.

core/src/apps/neo/get_address.py (1)

36-36: LGTM: Network name updated to "Neo N3"

The parameter value change aligns with network naming across the codebase.

core/src/apps/common/passphrase.py (1)

67-68: LGTM: Good addition of cancel handling

The check for cancelled passphrase is a needed safeguard.

core/src/apps/sui/sign_tx.py (5)

1-2: Import needed for gc.collect()

Necessary import for memory management.


35-35: Better performance with extend

Using extend() instead of += improves memory usage.


44-44: Better performance with extend

Using extend() instead of += improves memory usage.


62-63: Memory optimization

Good practice to collect garbage before processing chunks.


47-47:

✅ Verification successful

Verify parameter type

Confirm blind_sign_common accepts bytearray directly without bytes() conversion.


🏁 Script executed:

#!/bin/bash
grep -r "def confirm_blind_sign_common" --include="*.py" .

Length of output: 143


Parameter type verified.
The function in core/src/trezor/ui/layouts/lvgl/__init__.py accepts a bytearray directly. No conversion is needed.

core/src/apps/common/signverify.py (2)

46-48: Good memory management for large messages

Collecting garbage for large messages prevents memory issues.


53-54: Garbage collection in exception handler

Smart to free memory when handling decode errors.

core/src/trezor/uart.py (1)

112-118: Good enhancement to fingerprint failure handling.

The code now displays context-sensitive error messages for fingerprint authentication failures directly in the PIN input screen, improving the user feedback experience.

core/src/apps/management/recovery_device/layout.py (1)

156-166: Improved mnemonic validation flow.

The function now takes a list of mnemonic words and returns context-appropriate feedback via the InvalidMnemonic screen, supporting the mnemonic editing feature.

core/src/trezor/lvglui/scrs/passphrase.py (3)

9-9: Function signature properly updated.

The __init__ method now accepts an optional result parameter with proper type annotation.


22-24: Good implementation of passphrase editing.

Setting the text and cursor position enables the user to edit previously entered passphrases.


38-39: Variable name improved.

Renamed from 'input' to 'input_text' avoiding confusion with Python's built-in function.

core/src/apps/sui/sign_message.py (1)

27-36: More efficient hashing implementation.

The sequential update approach eliminates unnecessary string concatenation while maintaining the same cryptographic result.

core/src/apps/management/recovery_device/homescreen.py (4)

13-13: Necessary import for new functionality.

Import of request_word function is needed for the new mnemonic editing feature.


108-108: Initialize variable before use.

Good practice to initialize words to None at start.


111-127: Improved control flow for recovery process.

Better structured approach with clearer error handling.


136-156: New feature: edit individual mnemonic words.

This implementation allows users to correct specific words in an invalid mnemonic instead of starting over.

core/src/trezor/lvglui/scrs/recovery_device.py (6)

1-7: Necessary imports for new UI component.

Added imports for LCD control and UI components.


14-14: Type annotation added.

Better code clarity with type hints.


98-123: New InvalidMnemonic UI class.

Implements grid layout for displaying invalid mnemonic words.


124-159: UI components for word selection.

Word display with proper styling and layout.


162-169: Click handling for word selection.

Properly identifies selected word and publishes index.


170-179: Event handling for cancel button.

Handles "Start Over" button action correctly.

core/src/trezor/lvglui/scrs/template.py (4)

608-608: Horizontal padding added.

The button now has proper spacing for better visual appearance.


1296-1296: Fixed page size for content display.

The page size parameter ensures consistent viewing experience.


2399-2414: Enhanced passphrase workflow with dynamic button text and warning.

The new parameter from_device controls the cancel button text, showing "Edit" when appropriate. The warning banner alerts users about the risk of forgetting their passphrase.


2418-2418: Aligned panel with warning banner.

Panel alignment adjusted to accommodate the new warning banner.

core/src/trezor/lvglui/scrs/pinscreen.py (8)

181-185: Subtitle extracted to local variable before use.

Improves code readability by making the parameter flow clearer.


197-210: Improved subtitle styling with dynamic background.

Background color now changes based on content, making error messages more visible.


212-214: Consistent subtitle alignment.

Subtitle position now properly calculated relative to title height.


228-239: Added method to change subtitle dynamically.

Centralizes subtitle update logic for consistent appearance.


247-258: Animation setup for fingerprint prompt.

Animation parameters properly configured as instance attributes.


269-271: Enhanced cleanup in refresh_fingerprint_prompt.

Proper attribute deletion and subtitle clearing.


275-292: Added fingerprint error feedback.

Different error messages based on failure type improve user experience.


301-304: Renamed variable to avoid shadowing built-in.

Changed input to input_text to avoid shadowing Python's built-in function.

core/src/trezor/ui/layouts/lvgl/__init__.py (4)

755-755: Increased function flexibility by accepting bytearray param

The function now accepts a bytearray type for the data parameter, expanding its flexibility.


1121-1139: Added passphrase editing capability

Loop implementation allows correcting passphrase inputs before commitment, matching PR objectives for improved input editing.


1482-1482: Extended raw_message param to accept bytearray

Function now accepts both bytes and bytearray types for the raw_message parameter.


762-765:

❓ Verification inconclusive

Logic change for large data handling

Different prefix behavior based on data size could cause display inconsistency.


🏁 Script executed:

# Check if there are examples of this function being called with large data
grep -r "confirm_data" --include="*.py" . | grep -v "__init__.py"

Length of output: 2173


Data display inconsistency detected

  • Data longer than 1024 bytes omits the "0x" prefix.
  • Confirm that all consumers of confirm_data handle this formatting appropriately.

@somebodyLi somebodyLi enabled auto-merge (squash) April 11, 2025 02:32
@somebodyLi somebodyLi merged commit 09b3718 into main Apr 11, 2025
7 checks passed
@somebodyLi somebodyLi deleted the feat/misc branch April 11, 2025 03:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants