trezor-suite
trezor-suite copied to clipboard
BT transport
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
- There is
nativeBleManager.tswhich 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 ofusbApi
@suite-native/app
EXPO_PUBLIC_BLUETOOTH_ENABLEDenv variable - this needs to betruebefore 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
- Basically UI for BT (Scanning, connecting, permissions, errors, edge cases...)
- 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:
π¨ 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 | Note | Source | CI |
|---|---|---|---|---|
| Unstable ownership | npm/[email protected] |
| π« |
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
@SocketSecurity ignore npm/[email protected]
π Expo preview is ready!
- Project β trezor-suite-preview
- Platforms β android, ios
- Scheme β trezorsuitelite
- Runtime Version β 23
- More info
Learn more about π Expo Github Action
[!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
@coderabbitaiin 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
@coderabbitaiin 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 pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai generate docstringsto generate docstrings for this PR. (Beta)@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile 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.
Bluetooth functionality implemented in https://github.com/trezor/trezor-suite/pull/19125.