Merge #143: fix installer register descriptor error and add info

e01fd9b26facc2d01ed0ff0c4098dc93cfee7915 installer: make only xpub editable (edouard)
0969565b7ed0f1a08baa289f722a49c83f64003c fix installer register error (edouard)

Pull request description:

  - [x] fix register descriptor error
  - [x] ask only for xpub without wildcard

ACKs for top commit:
  edouardparis:
    Self-ACK e01fd9b26facc2d01ed0ff0c4098dc93cfee7915

Tree-SHA512: 4874f0ebfe5530590760f10debe5546c588e21124e6088dab9b60a2a8449a673cec80da0ca9de58250307a60acc9823c0957ea05f94cd5d28ff03b44e2cf6574
This commit is contained in:
edouard 2022-12-07 15:51:41 +01:00
commit 2aede0bc76
No known key found for this signature in database
GPG Key ID: E65F7A089C20DC8F
3 changed files with 44 additions and 25 deletions

View File

@ -6,10 +6,10 @@ use liana::{
descriptors::MultipathDescriptor,
miniscript::{
bitcoin::{
util::bip32::{DerivationPath, Fingerprint},
util::bip32::{DerivationPath, ExtendedPubKey, Fingerprint},
Network,
},
descriptor::{DescriptorMultiXKey, DescriptorPublicKey, Wildcard},
descriptor::DescriptorPublicKey,
},
};
@ -124,13 +124,13 @@ impl Step for DefineDescriptor {
fn apply(&mut self, ctx: &mut Context) -> bool {
ctx.bitcoin_config.network = self.network;
// descriptor forms for import or creation cannot be both empty or filled.
let user_key = DescriptorPublicKey::from_str(&self.user_xpub.value);
let user_key = DescriptorPublicKey::from_str(&format!("{}/<0;1>/*", &self.user_xpub.value));
self.user_xpub.valid = user_key.is_ok();
if let Ok(key) = &user_key {
self.user_xpub.valid = check_key_network(key, self.network);
}
let heir_key = DescriptorPublicKey::from_str(&self.heir_xpub.value);
let heir_key = DescriptorPublicKey::from_str(&format!("{}/<0;1>/*", &self.heir_xpub.value));
self.heir_xpub.valid = heir_key.is_ok();
if let Ok(key) = &heir_key {
self.heir_xpub.valid = check_key_network(key, self.network);
@ -297,30 +297,47 @@ impl GetHardwareWalletXpubModal {
}
}
pub struct XKey {
origin: Option<(Fingerprint, DerivationPath)>,
key: ExtendedPubKey,
}
impl std::fmt::Display for XKey {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
if let Some((ref master_id, ref master_deriv)) = self.origin {
std::fmt::Formatter::write_str(f, "[")?;
for byte in master_id.into_bytes().iter() {
write!(f, "{:02x}", byte)?;
}
for child in master_deriv {
write!(f, "/{}", child)?;
}
std::fmt::Formatter::write_str(f, "]")?;
}
self.key.fmt(f)?;
Ok(())
}
}
async fn get_extended_pubkey(
hw: std::sync::Arc<dyn async_hwi::HWI + Send + Sync>,
fingerprint: Fingerprint,
network: Network,
) -> Result<DescriptorPublicKey, Error> {
) -> Result<XKey, Error> {
let derivation_path = DerivationPath::from_str(if network == Network::Bitcoin {
LIANA_STANDARD_PATH
} else {
LIANA_TESTNET_STANDARD_PATH
})
.unwrap();
let xkey = hw
let key = hw
.get_extended_pubkey(&derivation_path, false)
.await
.map_err(Error::from)?;
Ok(DescriptorPublicKey::MultiXPub(DescriptorMultiXKey {
Ok(XKey {
origin: Some((fingerprint, derivation_path)),
derivation_paths: vec![
DerivationPath::from_str("m/0").unwrap(),
DerivationPath::from_str("m/1").unwrap(),
],
xkey,
wildcard: Wildcard::Unhardened,
}))
key,
})
}
pub struct ImportDescriptor {

View File

@ -148,6 +148,9 @@ pub fn define_descriptor<'a>(
.push(text("Your public key:").bold())
.push(
Row::new()
.push(button::border(Some(icon::chip_icon()), "Import").on_press(
Message::DefineDescriptor(message::DefineDescriptor::ImportUserHWXpub),
))
.push(
form::Form::new("Xpub", user_xpub, |msg| {
Message::DefineDescriptor(message::DefineDescriptor::UserXpubEdited(msg))
@ -158,11 +161,9 @@ pub fn define_descriptor<'a>(
"Please enter correct tpub"
})
.size(20)
.padding(10),
.padding(12),
)
.push(button::primary(Some(icon::chip_icon()), "Import").on_press(
Message::DefineDescriptor(message::DefineDescriptor::ImportUserHWXpub),
))
.push(Container::new(text("/<0;1>/*")))
.spacing(5)
.align_items(Alignment::Center),
)
@ -172,6 +173,9 @@ pub fn define_descriptor<'a>(
.push(text("Public key of the recovery key:").bold())
.push(
Row::new()
.push(button::border(Some(icon::chip_icon()), "Import").on_press(
Message::DefineDescriptor(message::DefineDescriptor::ImportHeirHWXpub),
))
.push(
form::Form::new("Xpub", heir_xpub, |msg| {
Message::DefineDescriptor(message::DefineDescriptor::HeirXpubEdited(msg))
@ -182,11 +186,9 @@ pub fn define_descriptor<'a>(
"Please enter correct tpub"
})
.size(20)
.padding(10),
.padding(12),
)
.push(button::primary(Some(icon::chip_icon()), "Import").on_press(
Message::DefineDescriptor(message::DefineDescriptor::ImportHeirHWXpub),
))
.push(Container::new(text("/<0;1>/*")))
.spacing(5)
.align_items(Alignment::Center),
)
@ -217,7 +219,7 @@ pub fn define_descriptor<'a>(
.push(col_user_xpub)
.push(col_sequence)
.push(col_heir_xpub)
.spacing(20),
.spacing(25),
)
.push(
if user_xpub.value.is_empty()
@ -326,7 +328,7 @@ pub fn register_descriptor<'a>(
.spacing(10)
.max_width(1000),
))
.push_maybe(error.map(|e| card::error("Failed to import xpub", e.to_string())))
.push_maybe(error.map(|e| card::error("Failed to register descriptor", e.to_string())))
.push(
Column::new()
.push(

View File

@ -81,7 +81,7 @@ pub fn error<'a, T: 'a>(message: &'static str, error: String) -> widget::Contain
Row::new()
.spacing(20)
.align_items(iced::Alignment::Center)
.push(icon::block_icon().style(color::ALERT))
.push(icon::warning_icon().style(color::ALERT))
.push(text(message).style(color::ALERT)),
error,
widget::tooltip::Position::Bottom,