Skip to content

Commit 9f5ad3e

Browse files
committed
HWI: add get_extended_pubkey_display()
1 parent 5a4d634 commit 9f5ad3e

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

src/bitbox.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,28 @@ impl<T: Runtime + Sync + Send> HWI for BitBox02<T> {
210210
Ok(Xpub::from_str(&fg).map_err(|e| HWIError::Device(e.to_string()))?)
211211
}
212212

213+
async fn get_extended_pubkey_display(&self, path: &DerivationPath) -> Result<Xpub, HWIError> {
214+
let fg = self
215+
.client
216+
.btc_xpub(
217+
if self.network == bitcoin::Network::Bitcoin {
218+
pb::BtcCoin::Btc
219+
} else {
220+
pb::BtcCoin::Tbtc
221+
},
222+
&Keypath::from(path),
223+
if self.network == bitcoin::Network::Bitcoin {
224+
pb::btc_pub_request::XPubType::Xpub
225+
} else {
226+
pb::btc_pub_request::XPubType::Tpub
227+
},
228+
true,
229+
)
230+
.await
231+
.map_err(|e| HWIError::Device(e.to_string()))?;
232+
Ok(Xpub::from_str(&fg).map_err(|e| HWIError::Device(e.to_string()))?)
233+
}
234+
213235
async fn display_address(&self, script: &AddressScript) -> Result<(), HWIError> {
214236
match script {
215237
AddressScript::P2TR(path) => {

src/ledger.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ impl<T: Transport + Sync + Send> HWI for Ledger<T> {
9797
.await?)
9898
}
9999

100+
async fn get_extended_pubkey_display(&self, path: &DerivationPath) -> Result<Xpub, HWIError> {
101+
Ok(self
102+
.client
103+
.get_extended_pubkey(path, true)
104+
.await?)
105+
}
106+
100107
async fn display_address(&self, script: &AddressScript) -> Result<(), HWIError> {
101108
match script {
102109
AddressScript::P2TR(path) => {

src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ pub trait HWI: Debug {
7575
async fn get_master_fingerprint(&self) -> Result<Fingerprint, Error>;
7676
/// Get the xpub with the given derivation path.
7777
async fn get_extended_pubkey(&self, path: &DerivationPath) -> Result<Xpub, Error>;
78+
/// Get the xpub with the given derivation path, will ask user ACK for non "standard"
79+
/// derivation path on some devices.
80+
async fn get_extended_pubkey_display(&self, path: &DerivationPath) -> Result<Xpub, Error> {
81+
self.get_extended_pubkey(path).await
82+
}
7883
/// Register a new wallet policy.
7984
async fn register_wallet(&self, name: &str, policy: &str) -> Result<Option<[u8; 32]>, Error>;
8085
/// Returns true if the wallet is registered on the device.

0 commit comments

Comments
 (0)