use bitcoin_miniscript::{MiniscriptKey, ToPublicKey};
use elements::bitcoin::key::XOnlyPublicKey;
use hashes::sha256;
use std::fmt::{Debug, Display};
pub trait SimplicityKey: Clone + Eq + Ord + Debug + Display + std::hash::Hash {
type Sha256: Clone + Eq + Ord + Display + Debug + std::hash::Hash;
}
impl<Pk: MiniscriptKey> SimplicityKey for Pk {
type Sha256 = <Pk as MiniscriptKey>::Sha256;
}
pub trait ToXOnlyPubkey: SimplicityKey {
fn to_x_only_pubkey(&self) -> XOnlyPublicKey;
fn to_sha256(hash: &Self::Sha256) -> sha256::Hash;
}
impl<Pk: ToPublicKey> ToXOnlyPubkey for Pk {
fn to_x_only_pubkey(&self) -> XOnlyPublicKey {
<Pk as ToPublicKey>::to_x_only_pubkey(self)
}
fn to_sha256(hash: &Self::Sha256) -> sha256::Hash {
<Pk as ToPublicKey>::to_sha256(hash)
}
}
pub trait Translator<P, Q, E>
where
P: SimplicityKey,
Q: SimplicityKey,
{
fn pk(&mut self, pk: &P) -> Result<Q, E>;
fn sha256(&mut self, sha256: &P::Sha256) -> Result<Q::Sha256, E>;
}