feat: expose custom transport API via from_transport()#126
Conversation
5ddf6ee to
f2f9922
Compare
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; |
There was a problem hiding this comment.
How about pub use comminucation::ReadWrite instead, to keep the public API surface smaller?
|
Applied both suggestions:
Built and verified successfully in our downstream app on both desktop |
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 I squashed your two commits, added a version-bump commit and published this change as v0.13.0. |
|
Thanks for the quick review and for cutting the release! |
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.