Skip to content

Commit 28ccc8f

Browse files
committed
common: fix Signer::is_mainnet for ledger
1 parent 8668536 commit 28ccc8f

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lwk_common/src/signer.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::str::FromStr;
33
use elements::{
44
bitcoin::{
55
self,
6-
bip32::{DerivationPath, Fingerprint, Xpub},
6+
bip32::{ChildNumber, DerivationPath, Fingerprint, Xpub},
77
XKeyIdentifier,
88
},
99
pset::PartiallySignedTransaction,
@@ -58,6 +58,18 @@ pub trait Signer {
5858
}
5959

6060
fn is_mainnet(&self) -> Result<bool, Self::Error> {
61-
Ok(self.xpub()?.network == bitcoin::NetworkKind::Main)
61+
let xpub = match self.xpub() {
62+
Ok(xpub) => xpub,
63+
Err(_) => {
64+
// We are probably on a Ledger that won't return the master xpub
65+
let path = [
66+
ChildNumber::from_hardened_idx(44).expect("static"),
67+
ChildNumber::from_hardened_idx(1).expect("static"), // TODO: work on mainnet?
68+
ChildNumber::from_hardened_idx(0).expect("static"),
69+
];
70+
self.derive_xpub(&DerivationPath::from_iter(path))?
71+
}
72+
};
73+
Ok(xpub.network == bitcoin::NetworkKind::Main)
6274
}
6375
}

0 commit comments

Comments
 (0)