use std::collections::{BTreeMap, HashMap}; use std::fmt; use std::sync::Arc; use bitcoin::hashes::hash160; use bitcoin::secp256k1::Secp256k1; use bitcoin::util::bip32::{ChildNumber, DerivationPath, Fingerprint}; use bitcoin::util::psbt; use bitcoin::{PublicKey, Script, TxOut}; use miniscript::descriptor::{DescriptorPublicKey, DescriptorXKey, InnerXKey}; pub use miniscript::{ Descriptor, Legacy, Miniscript, MiniscriptKey, ScriptContext, Segwitv0, Terminal, ToPublicKey, }; pub mod checksum; pub mod error; pub mod policy; // use crate::wallet::utils::AddressType; use crate::wallet::signer::SignersContainer; pub use self::checksum::get_checksum; use self::error::Error; pub use self::policy::Policy; pub type ExtendedDescriptor = Descriptor; type HDKeyPaths = BTreeMap; pub trait ExtractPolicy { fn extract_policy( &self, signers: Arc>, ) -> Result, Error>; } pub trait XKeyUtils { fn full_path(&self, append: &[ChildNumber]) -> DerivationPath; fn root_fingerprint(&self) -> Fingerprint; } impl XKeyUtils for DescriptorXKey { fn full_path(&self, append: &[ChildNumber]) -> DerivationPath { let full_path = match &self.source { &Some((_, ref path)) => path .into_iter() .chain(self.derivation_path.into_iter()) .cloned() .collect(), &None => self.derivation_path.clone(), }; if self.is_wildcard { full_path .into_iter() .chain(append.into_iter()) .cloned() .collect() } else { full_path } } fn root_fingerprint(&self) -> Fingerprint { match &self.source { &Some((fingerprint, _)) => fingerprint.clone(), &None => self.xkey.xkey_fingerprint(), } } } pub trait DescriptorMeta: Sized { fn is_witness(&self) -> bool; fn get_hd_keypaths(&self, index: u32) -> Result; fn is_fixed(&self) -> bool; fn derive_from_hd_keypaths(&self, hd_keypaths: &HDKeyPaths) -> Option; fn derive_from_psbt_input(&self, psbt_input: &psbt::Input, utxo: Option) -> Option; // fn address_type(&self) -> Option; } pub trait DescriptorScripts { fn psbt_redeem_script(&self) -> Option