Skip to content
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ pub trait HWI: Debug {
async fn get_master_fingerprint(&self) -> Result<Fingerprint, Error>;
/// 3. Get the xpub with the given derivation path.
async fn get_extended_pubkey(&self, path: &DerivationPath) -> Result<Xpub, Error>;
/// 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<Xpub, Error>;
/// 4. Register a new wallet policy
async fn register_wallet(&self, name: &str, policy: &str) -> Result<Option<[u8; 32]>, Error>;
/// 5. Returns true if the wallet is registered
Expand Down
2 changes: 1 addition & 1 deletion cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
22 changes: 22 additions & 0 deletions src/bitbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,28 @@ impl<T: Runtime + Sync + Send> HWI for BitBox02<T> {
Ok(Xpub::from_str(&fg).map_err(|e| HWIError::Device(e.to_string()))?)
}

async fn get_extended_pubkey_display(&self, path: &DerivationPath) -> Result<Xpub, HWIError> {
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) => {
Expand Down
4 changes: 4 additions & 0 deletions src/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ impl<T: Transport + Sync + Send> HWI for Ledger<T> {
.await?)
}

async fn get_extended_pubkey_display(&self, path: &DerivationPath) -> Result<Xpub, HWIError> {
Ok(self.client.get_extended_pubkey(path, true).await?)
}

async fn display_address(&self, script: &AddressScript) -> Result<(), HWIError> {
match script {
AddressScript::P2TR(path) => {
Expand Down
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ pub trait HWI: Debug {
async fn get_master_fingerprint(&self) -> Result<Fingerprint, Error>;
/// Get the xpub with the given derivation path.
async fn get_extended_pubkey(&self, path: &DerivationPath) -> Result<Xpub, Error>;
/// 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<Xpub, Error> {
self.get_extended_pubkey(path).await
}
/// Register a new wallet policy.
async fn register_wallet(&self, name: &str, policy: &str) -> Result<Option<[u8; 32]>, Error>;
/// Returns true if the wallet is registered on the device.
Expand Down
Loading