Skip to content

Expose transport-free BitBox02 protocol primitives - #140

Open
trevarj wants to merge 23 commits into
BitBoxSwiss:masterfrom
trevarj:trevarj/bhwi_protocol
Open

trevarj wants to merge 23 commits into
BitBoxSwiss:masterfrom
trevarj:trevarj/bhwi_protocol

Conversation

@trevarj

@trevarj trevarj commented Nov 26, 2026 •

Copy link
Copy Markdown

BHWI #81 tracks replacing copied vendor protocol code in BHWI. Today BHWI maintains its own BitBox02 wire and signing code because using the async client would also bring in its command sequencing and I/O model. Those copies can drift from upstream, including when signature validation is tightened.

This PR lets BHWI use the same protocol primitives as the BitBox client while keeping its own start / exchange / end interpreter, pairing state, and wallet ownership checks. Callers still provide transport and runtime, including for WASM and FFI. Once these APIs are released, BHWI can depend on the published crate instead of maintaining a fork.

  • Make default-features = false usable without device I/O, an async runtime, or OS randomness. The default build retains the existing client. Consumers that disable defaults but use the client can enable client, plus persistence or clock for those APIs.
  • Expose shared protobuf request builders and response parsers, caller-keyed Noise handshakes, compact and recoverable ECDSA and Anti-Klepto checks, and U2F/HWW/INFO codecs.
  • Share firmware-aware Bitcoin PSBT preparation and signature application, including a path for callers that verify wallet ownership themselves.

The U2F size and framing fixes overlap with #137. This PR does not include its host passphrase or typed device-state changes.

Verified with rustfmt, native no-default unit tests, a no-default WASM build check, Clippy with USB and simulator features, and the Bitcoin/PSBT tests against the pinned simulator matrix.

- Keep existing clients, persistence, and clock APIs enabled by default.
- Allow consumers to build the protocol without transport, runtime, or OS entropy.
- Share encoding and decoding with the convenience client.
- Preserve raw device error codes and messages before client error mapping.
- Expose explicit entropy, timestamp, and timezone payloads without client I/O.
- Reject malformed root fingerprints instead of returning arbitrary-length hex.
- Reuse shared xpub, address, and script-registration codecs in the client.
- Preserve protobuf field presence for paths, names, and nested responses.
- Keep ephemeral generation and pairing state in the client.
- Verify caller-supplied keys, pairing-code formatting, and encrypted exchanges with deterministic vectors.
- Port the final-sequence, payload-length, and error-propagation fixes from BitBoxSwiss#137.
- Validate incoming continuation headers and preserve incremental whole-report decoding.
- Read and write complete simulator reports over TCP.
- Share signing requests, reply parsers, and firmware gates without moving the client loop.
- Expose borrowed paths and reusable PSBT payloads; return an error for unsupported unforced scripts.
- Retain the convenience client’s fingerprint lookup and use one lowering path.
- Validate metadata cardinality and preserve firmware-aware output configuration.
- Reject mismatched input and signature counts before mutating the PSBT.
- Apply ECDSA and Taproot signatures without dropping unrelated entries.
- Parse acknowledgements without copying their payloads.
- Preserve client retry and reconnect behavior around the shared codecs.
- Apply rustfmt to the extracted client paths.
- Compile the ETH utility only for the client and its tests.
- Document the feature boundary and the caller’s fresh-ephemeral-key requirement.
- Check individual feature builds and guard the normal dependency closure.
- Keep the existing client, simulator, USB, and example matrix.
- Check the non-witness output index and preserve witness UTXO precedence.
- Zero U2F report padding and reject bad continuation headers as reports arrive.
- Reject empty reads, short writes, and missing initialized flags in modern INFO replies.
- Reject invalid compact scalars and high-S signatures without parsing twice.
- Document caller-owned signature verification and cover rejection before insertion.
- Reject nested replies to top-level requests and top-level replies to nested requests.
- Keep both envelopes supported by the standalone parser.
- Report adapter encoding errors as Write and retain detailed codec errors.
- Specify per-signature entropy, commitment ordering, and the verification boundary.
@trevarj trevarj changed the title # Expose transport-free BitBox02 protocol primitives Expose transport-free BitBox02 protocol primitives Nov 26, 2026
@trevarj

trevarj commented Nov 26, 2026

Copy link
Copy Markdown
Author

Probably should rebase after #137 is merged.

This branch has not been deployed

No deployments
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.

1 participant