use std::{
fmt::{Debug, Display},
hash::Hash,
};
use datasize::DataSize;
use serde::{de::DeserializeOwned, Serialize};
use crate::NodeRng;
pub trait NodeIdT: Clone + Display + Debug + Send + Eq + Hash + 'static {}
impl<I> NodeIdT for I where I: Clone + Display + Debug + Send + Eq + Hash + 'static {}
pub(crate) trait ValidatorIdT: Eq + Ord + Clone + Debug + Hash {}
impl<VID> ValidatorIdT for VID where VID: Eq + Ord + Clone + Debug + Hash {}
pub(crate) trait ConsensusValueT:
Eq + Clone + Debug + Hash + Serialize + DeserializeOwned
{
fn needs_validation(&self) -> bool;
}
pub(crate) trait HashT:
Eq + Ord + Copy + Clone + Debug + Display + Hash + Serialize + DeserializeOwned
{
}
impl<H> HashT for H where
H: Eq + Ord + Copy + Clone + Debug + Display + Hash + Serialize + DeserializeOwned
{
}
pub(crate) trait ValidatorSecret {
type Hash;
type Signature: Eq + PartialEq + Clone + Debug + Hash + Serialize + DeserializeOwned;
fn sign(&self, hash: &Self::Hash, rng: &mut NodeRng) -> Self::Signature;
}
pub(crate) trait Context: Clone + Debug + Eq + Ord + Hash {
type ConsensusValue: ConsensusValueT + DataSize;
type ValidatorId: ValidatorIdT;
type ValidatorSecret: ValidatorSecret<Hash = Self::Hash, Signature = Self::Signature>;
type Signature: Copy + Clone + Debug + Eq + Hash + Serialize + DeserializeOwned;
type Hash: HashT;
type InstanceId: HashT;
fn hash(data: &[u8]) -> Self::Hash;
fn verify_signature(
hash: &Self::Hash,
public_key: &Self::ValidatorId,
signature: &<Self::ValidatorSecret as ValidatorSecret>::Signature,
) -> bool;
}