[keys] Add a way to restrict the networks in which keys are valid

Thanks to the `ToWalletDescriptor` trait we can also very easily validate the checksum
for descriptors that are loaded from strings, if they contain one. Fixes #20.
This commit is contained in:
Alekos Filini
2020-09-21 15:44:07 +02:00
parent bc8acaf088
commit c51ba4a99f
8 changed files with 405 additions and 141 deletions

View File

@@ -48,6 +48,8 @@ pub enum Error {
required: crate::types::FeeRate,
},
Key(crate::keys::KeyError),
ChecksumMismatch,
DifferentDescriptorStructure,
@@ -114,6 +116,17 @@ impl_error!(
);
impl_error!(crate::wallet::signer::SignerError, Signer);
impl From<crate::keys::KeyError> for Error {
fn from(key_error: crate::keys::KeyError) -> Error {
match key_error {
crate::keys::KeyError::Miniscript(inner) => Error::Miniscript(inner),
crate::keys::KeyError::BIP32(inner) => Error::BIP32(inner),
crate::keys::KeyError::InvalidChecksum => Error::ChecksumMismatch,
e @ _ => Error::Key(e),
}
}
}
impl_error!(bitcoin::consensus::encode::Error, Encode);
impl_error!(miniscript::Error, Miniscript);
impl_error!(bitcoin::util::bip32::Error, BIP32);