Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
05f4526
feat: make the BitBox client stack optional
trevarj Nov 26, 2026
0c020ad
feat: expose signature and Anti-Klepto validation
trevarj Nov 26, 2026
dfa50df
feat: expose the protobuf envelope codec
trevarj Nov 26, 2026
807eaf2
feat: share management request and response primitives
trevarj Nov 26, 2026
eb28bc6
feat(btc): share one-shot request and response primitives
trevarj Nov 26, 2026
4e33be8
feat(noise): expose caller-keyed handshake primitives
trevarj Nov 26, 2026
0361012
fix(u2f): expose framing and validate report boundaries
trevarj Nov 26, 2026
fe4b05c
feat(btc): expose signing primitives and payloads
trevarj Nov 26, 2026
6a324b7
feat(btc): lower PSBTs with caller-resolved keys
trevarj Nov 26, 2026
7ab0be4
feat(btc): share PSBT signature application
trevarj Nov 26, 2026
5da7359
feat: expose HWW and INFO framing primitives
trevarj Nov 26, 2026
6d026f8
style: finish feature-gated protocol cleanup
trevarj Nov 26, 2026
5f43a4f
docs: describe the transport-free protocol feature
trevarj Nov 26, 2026
ee49e1b
ci: verify the isolated native and WASM protocol surface
trevarj Nov 26, 2026
e4ad051
fix(btc): reject out-of-range PSBT previous outputs
trevarj Nov 26, 2026
5147879
fix(btc): require firmware 9.22 for separate output configs
trevarj Nov 26, 2026
55a1699
fix(noise): reject malformed pairing acknowledgements
trevarj Nov 26, 2026
5e21a19
fix: reject malformed or incomplete BitBox reports
trevarj Nov 26, 2026
ac45044
build: gate client-only hex and zeroize dependencies
trevarj Nov 26, 2026
0006cff
fix(btc): validate compact PSBT signatures
trevarj Nov 26, 2026
a07113f
fix(btc): preserve client signing reply envelopes
trevarj Nov 26, 2026
1f28df7
fix(u2f): preserve the public communication error enum
trevarj Nov 26, 2026
99a9718
docs(antiklepto): define the caller nonce contract
trevarj Nov 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt
targets: wasm32-unknown-unknown
- name: Enable simulators caching
uses: actions/cache@v4
with:
Expand All @@ -34,6 +35,7 @@ jobs:
- uses: dtolnay/rust-toolchain@beta
with:
components: clippy, rustfmt
targets: wasm32-unknown-unknown
- name: Enable simulators caching
uses: actions/cache@v4
with:
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog

## [Unreleased]
- Expose transport-free protobuf, Bitcoin, signature validation, Noise, and framing primitives
with `default-features = false`. Defaults retain the async convenience clients.
- Reject malformed fingerprint, pairing, and framing replies, and return an error for an
out-of-range previous output when lowering a PSBT.
- Reject malformed compact ECDSA signatures when applying signatures to a PSBT.
- Preserve the sign of positive EIP-712 signed integers supplied as JSON numbers.
- Reset unfinished sessions when connecting to firmware v9.28.0 or newer, allowing host
reconnects while the device remains powered on.
Expand Down
46 changes: 33 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,43 @@ keywords = ["bitbox", "api", "bitcoin"]
categories = ["api-bindings", "cryptography"]

[dependencies]
async-trait = "0.1.68"
async-trait = { version = "0.1.68", optional = true }
base32 = "0.5"
bitcoin = "0.32"
byteorder = "1.3.2"
getrandom = { version = "0.2" }
futures-util = { version = "0.3", default-features = false, features = ["std"] }
hex = { version = "0.4" }
getrandom = { version = "0.2", optional = true }
futures-util = { version = "0.3", default-features = false, features = ["std"], optional = true }
hex = { version = "0.4", optional = true }
noise-protocol = "0.2"
noise-rust-crypto = "0.6"
num-bigint = "0.4"
noise-rust-crypto = { version = "0.6", optional = true }
num-bigint = { version = "0.4", optional = true }
# If you change this, also change the version of prost-build in scripts/build-protos.rs
# and run `make build-protos`.
prost = "0.14"
semver = "1.0.17"
serde_json = { version = "1.0" }
serde_json = { version = "1.0", optional = true }
thiserror = "2.0"
zeroize = "1"
zeroize = { version = "1", optional = true }

chrono = { version = "0.4.38", default-features = false, features = ["clock"] }
chrono = { version = "0.4.38", default-features = false, features = ["clock"], optional = true }
hidapi = { version = "2.3", optional = true }
rlp = { version = "0.6", optional = true }
serde = { version = "1.0", features = ["derive"] }
serde = { version = "1.0", features = ["derive"], optional = true }
tokio = { version = "1", optional = true, features = ["time"] }

[dev-dependencies]
# For the base64 PSBT input/output in examples/btc_sign_psbt.rs.
bitcoin = { version = "0.32", features = ["base64"] }
futures-channel = "0.3"
hex = "0.4"
noise-rust-crypto = "0.6"
tokio = { version = "1", features = ["time", "macros", "rt", "fs"] }
reqwest = "0.12"
url = "2.5"
tiny-keccak = { version = "2.0", features = ["keccak"] }
rlp = "0.6"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
# Enable this to be able to get coverage using `cargo tarpaulin --features=simulator,tokio --out=Html` without compilation error.
# See https://github.com/rust-bitcoin/rust-bitcoinconsensus/pull/94
# bitcoinconsensus = { git = "https://github.com/rust-bitcoin/rust-bitcoinconsensus.git", rev = "788ce4d210f7fe6fae4414f5be80968216ba0fd8", default-features = false }
Expand Down Expand Up @@ -81,7 +85,7 @@ required-features = ["usb", "tokio/rt", "tokio/macros"]

[[example]]
name = "eth"
required-features = ["usb", "tokio/rt", "tokio/macros", "rlp"]
required-features = ["usb", "tokio/rt", "tokio/macros", "rlp", "persistence"]

[[example]]
name = "cardano"
Expand All @@ -92,8 +96,24 @@ name = "simulator"
required-features = ["simulator", "tokio/rt", "tokio/macros", "tokio/rt-multi-thread", "multithreaded"]

[features]
default = ["client", "persistence", "clock"]
runtime = ["dep:async-trait"]
read-write = ["dep:async-trait"]
client = [
"runtime",
"read-write",
"dep:futures-util",
"dep:getrandom",
"dep:hex",
"dep:noise-rust-crypto",
"dep:num-bigint",
"dep:zeroize",
]
persistence = ["dep:serde", "dep:serde_json"]
clock = ["client", "dep:chrono"]
usb = ["client", "dep:hidapi"]
simulator = ["client"]
tokio = ["runtime", "dep:tokio"]
# Implement Sync+Send for PairedBitBox and PairingBitBox.
# This may or may not cause trouble on macOS, see: https://github.com/libusb/hidapi/issues/503
multithreaded = []
usb = ["dep:hidapi"]
simulator = []
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ To run the example:

See [Cargo.toml](Cargo.toml) for further examples.

## Protocol-only use

Set `default-features = false` on `bitbox-api` to use the protobuf, Bitcoin, Noise,
signature validation, and framing primitives without the async client or its I/O
dependencies. The protocol-only library also builds for `wasm32-unknown-unknown`.
When initiating Noise yourself, supply a new cryptographically random ephemeral
key for each handshake. The caller owns pairing confirmation and transport.

The default features are `client`, `persistence`, and `clock`. With defaults
disabled, enable `client` for the async API, `persistence` for JSON Noise config
and typed Ethereum message signing, and `clock` for system-time mnemonic restore.
`runtime` and `read-write` can be enabled separately for custom implementations.

## Simulator tests

The integration tests in [tests/](tests/) run against BitBox02 simulators. The simulators are
Expand Down
15 changes: 15 additions & 0 deletions ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ examples=(

cargo fmt --check

cargo test --locked --lib --no-default-features
cargo check --locked --lib --no-default-features --target wasm32-unknown-unknown
for target in "$(rustc -vV | awk '$1 == "host:" { print $2 }')" wasm32-unknown-unknown; do
dependencies=$(cargo tree --locked --no-default-features --target "$target" \
-e normal,build --prefix none --format '{p}')
if grep -E '^(async-trait|chrono|futures-util|getrandom|hidapi|js-sys|noise-rust-crypto|serde|serde_json|tokio|wasm-bindgen|web-sys) ' <<< "$dependencies"; then
echo "Unexpected transport, platform, or client dependency for $target"
exit 1
fi
done

for feature in runtime read-write client persistence clock; do
cargo check --locked --lib --no-default-features --features "$feature"
done

for feature_set in "${features[@]}"; do
echo $feature_set
cargo test --tests --locked --features="$feature_set" -- --nocapture --test-threads 1
Expand Down
13 changes: 12 additions & 1 deletion src/antiklepto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::io::Write;

#[derive(Error, Debug)]
pub enum Error {
#[cfg(feature = "client")]
#[error("Failed generating antiklepto host nonce")]
GenNonce,
#[error("{0}")]
Expand All @@ -35,19 +36,27 @@ fn tagged_sha256(tag: &[u8], msg: &[u8]) -> [u8; 32] {
sha256::Hash::from_engine(engine).to_byte_array()
}

pub fn gen_host_nonce() -> Result<[u8; 32], Error> {
#[cfg(feature = "client")]
pub(crate) fn gen_host_nonce() -> Result<[u8; 32], Error> {
let mut result = [0u8; 32];
getrandom::getrandom(&mut result).map_err(|_| Error::GenNonce)?;
Ok(result)
}

/// Commits to a host nonce for one Anti-Klepto signature.
///
/// Generate a fresh, secret 32-byte nonce with a cryptographically secure RNG for each
/// signature. Send only the commitment until the signer returns its commitment, then
/// reveal the nonce and verify its contribution before accepting the signature.
pub fn host_commit(host_nonce: &[u8]) -> [u8; 32] {
tagged_sha256(b"s2c/ecdsa/data", host_nonce)
}

/// Verifies that `host_nonce` was used to tweak the nonce during signature generation according
/// to k' = k + H(signer_commitment, host_nonce) by checking that
/// k'*G = signer_commitment + H(signer_commitment, host_nonce)*G.
///
/// This does not verify the signature against the message and signing key.
pub fn verify_ecdsa(
host_nonce: &[u8],
signer_commitment: &[u8],
Expand All @@ -58,6 +67,8 @@ pub fn verify_ecdsa(
}

/// Validates a recoverable ECDSA signature and verifies its Anti-Klepto nonce contribution.
///
/// This does not verify the signature against the message and signing key.
pub fn verify_recoverable_ecdsa(
host_nonce: &[u8],
signer_commitment: &[u8],
Expand Down
Loading