diff --git a/README.md b/README.md index 2b870b4..6893e97 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,9 @@ pub trait HWI: Debug { async fn get_master_fingerprint(&self) -> Result; /// 3. Get the xpub with the given derivation path. async fn get_extended_pubkey(&self, path: &DerivationPath) -> Result; + /// Get the xpub with the given derivation path, will ask user ACK for non "standard" + /// derivation path on some devices. + async fn get_extended_pubkey_display(&self, path: &DerivationPath) -> Result; /// 4. Register a new wallet policy async fn register_wallet(&self, name: &str, policy: &str) -> Result, Error>; /// 5. Returns true if the wallet is registered diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 1c719f9..2b3b9ed 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -68,7 +68,7 @@ pub mod command { { if let Ok((device, _)) = device.wait_confirm().await { let mut bb02 = BitBox02::from(device).with_network(network); - if let Some(ref policy) = wallet.as_ref().map(|w| w.policy).flatten() { + if let Some(policy) = wallet.as_ref().and_then(|w| w.policy) { bb02 = bb02.with_policy(policy)?; } hws.push(bb02.into()); diff --git a/src/bitbox.rs b/src/bitbox.rs index 9210520..02c4e3d 100644 --- a/src/bitbox.rs +++ b/src/bitbox.rs @@ -210,6 +210,28 @@ impl HWI for BitBox02 { Ok(Xpub::from_str(&fg).map_err(|e| HWIError::Device(e.to_string()))?) } + async fn get_extended_pubkey_display(&self, path: &DerivationPath) -> Result { + let fg = self + .client + .btc_xpub( + if self.network == bitcoin::Network::Bitcoin { + pb::BtcCoin::Btc + } else { + pb::BtcCoin::Tbtc + }, + &Keypath::from(path), + if self.network == bitcoin::Network::Bitcoin { + pb::btc_pub_request::XPubType::Xpub + } else { + pb::btc_pub_request::XPubType::Tpub + }, + true, + ) + .await + .map_err(|e| HWIError::Device(e.to_string()))?; + Ok(Xpub::from_str(&fg).map_err(|e| HWIError::Device(e.to_string()))?) + } + async fn display_address(&self, script: &AddressScript) -> Result<(), HWIError> { match script { AddressScript::P2TR(path) => { diff --git a/src/ledger.rs b/src/ledger.rs index 48ab262..292b88c 100644 --- a/src/ledger.rs +++ b/src/ledger.rs @@ -97,6 +97,10 @@ impl HWI for Ledger { .await?) } + async fn get_extended_pubkey_display(&self, path: &DerivationPath) -> Result { + Ok(self.client.get_extended_pubkey(path, true).await?) + } + async fn display_address(&self, script: &AddressScript) -> Result<(), HWIError> { match script { AddressScript::P2TR(path) => { diff --git a/src/lib.rs b/src/lib.rs index da2fe93..76036be 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -75,6 +75,11 @@ pub trait HWI: Debug { async fn get_master_fingerprint(&self) -> Result; /// Get the xpub with the given derivation path. async fn get_extended_pubkey(&self, path: &DerivationPath) -> Result; + /// Get the xpub with the given derivation path, will ask user ACK for non "standard" + /// derivation path on some devices. + async fn get_extended_pubkey_display(&self, path: &DerivationPath) -> Result { + self.get_extended_pubkey(path).await + } /// Register a new wallet policy. async fn register_wallet(&self, name: &str, policy: &str) -> Result, Error>; /// Returns true if the wallet is registered on the device.