Skip to content

Commit 8675c38

Browse files
committed
add features() function
Helpful if clients want to conditionally make use of features without users running into a firmware version error.
1 parent bbca9df commit 8675c38

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/lib.rs

+17
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ pub struct BitBox<R: Runtime> {
7272

7373
pub type PairingCode = String;
7474

75+
#[cfg_attr(feature = "wasm", serde(rename_all = "camelCase"))]
76+
/// A list of features supported by the currently connected BitBox.
77+
pub struct Features {
78+
/// Can use `tag_cbor_sets` in `cardano_sign_transaction()`.
79+
pub cardano_tag_cbor_sets: bool,
80+
}
81+
7582
impl<R: Runtime> BitBox<R> {
7683
async fn from(
7784
device: Box<dyn communication::ReadWrite>,
@@ -351,6 +358,16 @@ impl<R: Runtime> PairedBitBox<R> {
351358
&self.communication.info.version
352359
}
353360

361+
/// Returns list of features supported by the currently connected BitBox.
362+
pub fn features(&self) -> Features {
363+
let version = self.version();
364+
let version_at_least =
365+
|major, minor, patch| *version >= semver::Version::new(major, minor, patch);
366+
Features {
367+
cardano_tag_cbor_sets: version_at_least(9, 22, 0),
368+
}
369+
}
370+
354371
/// Returns the hex-encoded 4-byte root fingerprint.
355372
pub async fn root_fingerprint(&self) -> Result<String, Error> {
356373
match self

tests/test_cardano.rs

+2
Original file line numberDiff line numberDiff line change
@@ -397,13 +397,15 @@ async fn test_cardano_transactions() {
397397
.unwrap()
398398
.matches(bitbox.version())
399399
{
400+
assert!(bitbox.features().cardano_tag_cbor_sets);
400401
let witness = bitbox.cardano_sign_transaction(transaction).await.unwrap();
401402
assert_eq!(witness.shelley_witnesses.len(), 1);
402403
assert_eq!(
403404
hex::encode(&witness.shelley_witnesses[0].public_key),
404405
"6b5d4134cfc66281827d51cb0196f1a951ce168c19ba1314233f43d39d91e2bc",
405406
);
406407
} else {
408+
assert!(!bitbox.features().cardano_tag_cbor_sets);
407409
assert!(matches!(
408410
bitbox.cardano_sign_transaction(transaction).await,
409411
Err(bitbox_api::error::Error::Version(">=9.22.0"))

0 commit comments

Comments
 (0)