Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add features() function #99

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 17 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ pub struct BitBox<R: Runtime> {

pub type PairingCode = String;

#[cfg_attr(feature = "wasm", serde(rename_all = "camelCase"))]
/// A list of features supported by the currently connected BitBox.
pub struct Features {
/// Can use `tag_cbor_sets` in `cardano_sign_transaction()`.
pub cardano_tag_cbor_sets: bool,
}

impl<R: Runtime> BitBox<R> {
async fn from(
device: Box<dyn communication::ReadWrite>,
Expand Down Expand Up @@ -351,6 +358,16 @@ impl<R: Runtime> PairedBitBox<R> {
&self.communication.info.version
}

/// Returns list of features supported by the currently connected BitBox.
pub fn features(&self) -> Features {
let version = self.version();
let version_at_least =
|major, minor, patch| *version >= semver::Version::new(major, minor, patch);
Features {
cardano_tag_cbor_sets: version_at_least(9, 22, 0),
}
}

/// Returns the hex-encoded 4-byte root fingerprint.
pub async fn root_fingerprint(&self) -> Result<String, Error> {
match self
Expand Down
2 changes: 2 additions & 0 deletions tests/test_cardano.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,13 +397,15 @@ async fn test_cardano_transactions() {
.unwrap()
.matches(bitbox.version())
{
assert!(bitbox.features().cardano_tag_cbor_sets);
let witness = bitbox.cardano_sign_transaction(transaction).await.unwrap();
assert_eq!(witness.shelley_witnesses.len(), 1);
assert_eq!(
hex::encode(&witness.shelley_witnesses[0].public_key),
"6b5d4134cfc66281827d51cb0196f1a951ce168c19ba1314233f43d39d91e2bc",
);
} else {
assert!(!bitbox.features().cardano_tag_cbor_sets);
assert!(matches!(
bitbox.cardano_sign_transaction(transaction).await,
Err(bitbox_api::error::Error::Version(">=9.22.0"))
Expand Down
Loading