trezor-suite icon indicating copy to clipboard operation
trezor-suite copied to clipboard

BT transport

Open Nodonisko opened this issue 1 year ago β€’ 1 comments

Description

POC of BT transport layer in Suite Mobile. Implemented using react-native-ble-plx lib which is used by all crypto apps that I explored. It's also nice for 3rd parties because they won't need to add extra native dependency and it will also help us avoid some conflicts (hopefully) that could occur when multiple libraries for BT access are used.

Also please keep in mind this is very first version, even there is lot edge cases handled, some stuff is missing for example erasing bonds (compared to @szymonlesisz PR). I also did not encountered any packet duplication (but I guess it can happen), but I think it's fine to omit it now and wait for new protocol which will solve it anyway.

Video: https://satoshilabs.slack.com/files/U02RLDSFCPP/F071BCP430S/screen-20240430-154355.mp4

Summary of changes

@trezor/transport-native-ble

  1. There is nativeBleManager.ts which is acting like desktop api in @szymonlesisz branch for desktop. It must be single instance and we must be able to import this instance in app UI to handle stuff like connecting, scanning etc. 2.bleApi.ts - it's basically BT version of usbApi

@suite-native/app

  1. EXPO_PUBLIC_BLUETOOTH_ENABLED env variable - this needs to be true before build to include some native code for requesting permission for BT (libraries will be included in all types build anyway, but at least it won't show extra permission in stores). By default this will be enabled for Debug and Develop builds so anyone can turn ON BT for testing.

@suite-native/bluetooth

  1. Basically UI for BT (Scanning, connecting, permissions, errors, edge cases...)
  2. Feature flag in @suite-native/bluetooth - This is special kind of static feature flag because it must be persisted because app must be restarted when it's changed. Once we will support multi-transport restart woudn't be neccessary.

Related Issue

Resolve #11751

Screenshots:

Nodonisko avatar Apr 03 '24 09:04 Nodonisko

🚨 Potential security issues detected. Learn more about Socket for GitHub β†—οΈŽ

To accept the risk, merge this PR and you will not be notified again.

Alert Package NoteSourceCI
Unstable ownership npm/[email protected] 🚫

View full reportβ†—οΈŽ

Next steps

What is unstable ownership?

A new collaborator has begun publishing package versions. Package stability and security risk may be elevated.

Try to reduce the number of authors you depend on to reduce the risk to malicious actors gaining access to your supply chain. Packages should remove inactive collaborators with publishing rights from packages on npm.

Take a deeper look at the dependency

Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev.

Remove the package

If you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency.

Mark a package as acceptable risk

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of ecosystem/package-name@version specifiers. e.g. @SocketSecurity ignore npm/[email protected] or ignore all packages with @SocketSecurity ignore-all

socket-security[bot] avatar Apr 30 '24 12:04 socket-security[bot]

πŸš€ Expo preview is ready!

  • Project β†’ trezor-suite-preview
  • Platforms β†’ android, ios
  • Scheme β†’ trezorsuitelite
  • Runtime Version β†’ 23
  • More info

Learn more about 𝝠 Expo Github Action

github-actions[bot] avatar Jan 15 '25 16:01 github-actions[bot]

[!WARNING] There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

πŸ”§ ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

error Error: http://10.0.0.28:4873/@trezor%2feslint: no such package available at params.callback [as _callback] (/opt/yarn-v1.22.22/lib/cli.js:66685:18) at self.callback (/opt/yarn-v1.22.22/lib/cli.js:141415:22) at Request.emit (node:events:519:28) at Request. (/opt/yarn-v1.22.22/lib/cli.js:142387:10) at Request.emit (node:events:519:28) at IncomingMessage. (/opt/yarn-v1.22.22/lib/cli.js:142309:12) at Object.onceWrapper (node:events:633:28) at IncomingMessage.emit (node:events:531:35) at endReadableNT (node:internal/streams/readable:1698:12) at process.processTicksAndRejections (node:internal/process/task_queues:90:21)

Walkthrough

The pull request introduces comprehensive Bluetooth functionality for the Trezor Suite Native application. It includes the creation of a new @suite-native/bluetooth package with multiple components and hooks for managing Bluetooth device interactions. The implementation covers Bluetooth adapter state management, permission handling, device scanning, and connection processes. A new transport layer for Bluetooth (@trezor/transport-native-ble) has been added to support device communication. The changes enable Bluetooth device discovery, connection, and basic interaction capabilities, with feature flags to control Bluetooth functionality across different build configurations.

Assessment against linked issues

Objective Addressed Explanation
Create standalone package for BT βœ… A new @suite-native/bluetooth package has been created with comprehensive functionality
Handle permissions for BT βœ… Implemented useBluetoothPermissions hook with detailed permission management for iOS and Android
Pair BLE device ❓ Basic device scanning and connection components are implemented, but full pairing UX requires further validation
Generate Receive address on BLE device ❌ No explicit implementation for address generation over Bluetooth is present
Sign TX on BLE device ❌ Transaction signing over Bluetooth is not implemented in this PR

The implementation provides a solid foundation for Bluetooth functionality, with a focus on infrastructure and permission handling. Further development will be needed to complete the full set of Bluetooth device interaction capabilities.

✨ Finishing Touches
  • [ ] πŸ“ Generate Docstrings (Beta)

πŸͺ§ 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. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.

coderabbitai[bot] avatar Jan 31 '25 11:01 coderabbitai[bot]

Bluetooth functionality implemented in https://github.com/trezor/trezor-suite/pull/19125.

yanascz avatar Jun 04 '25 07:06 yanascz