feat: expose custom transport API via from_transport()#126
Open
frijolo wants to merge 2 commits into
Open
Conversation
Add a public BitBox::from_transport() that accepts any communication::ReadWrite implementation and performs the U2F-HID framing internally. This lets callers delegate raw USB I/O to platform-specific code (e.g. Android, where USB access requires Java APIs unavailable to hidapi) by implementing only the ReadWrite trait over their transport. - Make the communication module public to expose the ReadWrite trait and Error. - Remove the feature gate on FIRMWARE_CMD so from_transport (available without the usb/wasm/simulator features) can perform the framing.
frijolo
force-pushed
the
custom-transport
branch
from
July 14, 2026 09:25
5ddf6ee to
f2f9922
Compare
benma
requested changes
Jul 15, 2026
Comment on lines
118
to
122
Contributor
There was a problem hiding this comment.
Could reuse Self::from_transport here and in from_simulator below
|
|
||
| mod antiklepto; | ||
| mod communication; | ||
| pub mod communication; |
Contributor
There was a problem hiding this comment.
How about pub use comminucation::ReadWrite instead, to keep the public API surface smaller?
- from_hid_device and from_simulator now delegate to from_transport() instead of duplicating the U2fHidCommunication::from(...) call. - Keep the communication module private; re-export ReadWrite (and Error, which appears in its method signatures and is therefore required by any external implementor) from the crate root instead.
Author
|
Applied both suggestions:
Built and verified successfully in our downstream app on both desktop |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a public
BitBox::from_transport()constructor that accepts anycommunication::ReadWriteimplementation and performs the U2F-HID framing internally. This lets callers delegate raw USB I/O to platform-specific code, instead of relying onhidapi.Two small changes:
communicationmodule public, exposing theReadWritetrait andError.FIRMWARE_CMDsofrom_transport(available without theusb/wasm/simulatorfeatures) can perform the framing.Motivation
We want to drive a BitBox02 from Android, where USB access must go through the Java
UsbManagerAPI andhidapiis not available. The existing constructors (from_hid_device,usb::get_any_bitbox02) all assumehidapi, so there is currently no way to connect on such platforms.With
from_transport(), a caller implements only theReadWritetrait over their platform's transport (on Android, a channel bridged to the Java USB stack) and gets a fully functionalBitBox— the U2F-HID framing is handled by the library, exactly as it is for the USB path. Desktop/hidapicallers are unaffected.This mirrors how the official BitBoxApp already drives the device on Android: its
GoViewModel.javaopens the device throughUsbManager/UsbDeviceConnection, performs thebulkTransfer()I/O in Java, and hands aReadWriteCloserto the Go backend (nohidapion Android).from_transport()is simply the Rust/bitbox-apiequivalent of that pattern.What changed
src/lib.rs: newpub async fn from_transport(transport: Box<dyn communication::ReadWrite>, noise_config: Box<dyn NoiseConfig>) -> Result<BitBox<R>, Error>;mod communication→pub mod communication.src/communication.rs:FIRMWARE_CMDis no longer gated behindusb/wasm/simulator, sincefrom_transportneeds it without those features.No existing API changes; this is purely additive.
Testing
usbfeature.ReadWritetransport built onfrom_transport()— pairing, xpub export, wallet/policy registration, and PSBT signing (singlesig + multisig) all verified on-device.