1use bitcoin_miniscript::{MiniscriptKey, ToPublicKey};
4use elements::bitcoin::key::XOnlyPublicKey;
5use hashes::sha256;
6use std::fmt::{Debug, Display};
7
8pub trait SimplicityKey: Clone + Eq + Ord + Debug + Display + std::hash::Hash {
10 type Sha256: Clone + Eq + Ord + Display + Debug + std::hash::Hash;
12}
13
14impl<Pk: MiniscriptKey> SimplicityKey for Pk {
15 type Sha256 = <Pk as MiniscriptKey>::Sha256;
16}
17
18pub trait ToXOnlyPubkey: SimplicityKey {
20 fn to_x_only_pubkey(&self) -> XOnlyPublicKey;
22
23 fn to_sha256(hash: &Self::Sha256) -> sha256::Hash;
25}
26
27impl<Pk: ToPublicKey> ToXOnlyPubkey for Pk {
28 fn to_x_only_pubkey(&self) -> XOnlyPublicKey {
29 <Pk as ToPublicKey>::to_x_only_pubkey(self)
30 }
31
32 fn to_sha256(hash: &Self::Sha256) -> sha256::Hash {
33 <Pk as ToPublicKey>::to_sha256(hash)
34 }
35}
36
37pub trait Translator<P, Q, E>
39where
40 P: SimplicityKey,
41 Q: SimplicityKey,
42{
43 fn pk(&mut self, pk: &P) -> Result<Q, E>;
45
46 fn sha256(&mut self, sha256: &P::Sha256) -> Result<Q::Sha256, E>;
48}