use super::otext::{ExtReceiver, ExtSender};
use super::secp::{ProjectivePoint, Scalar};
use crate::tss::PartyId;
#[derive(Clone)]
pub struct PairOTState {
pub as_alice: ExtReceiver,
pub as_bob: ExtSender,
}
#[derive(Clone)]
pub struct Key {
pub n: usize,
pub t: usize,
pub idx: usize,
pub party_ids: Vec<PartyId>,
pub xi: Scalar,
pub big_xj: Vec<ProjectivePoint>,
pub ecdsa_pub: ProjectivePoint,
pub ot: Vec<Option<PairOTState>>,
pub chain_code: [u8; 32],
}
impl Key {
pub fn validate_basic(&self) -> Result<(), super::Error> {
use super::Error::Validation;
if self.n == 0 || self.t >= self.n {
return Err(Validation(format!("invalid (N={}, T={})", self.n, self.t)));
}
if self.idx >= self.n {
return Err(Validation(format!("Idx={} out of range", self.idx)));
}
if self.party_ids.len() != self.n || self.big_xj.len() != self.n || self.ot.len() != self.n
{
return Err(Validation("inconsistent N-length fields".into()));
}
if bool::from(self.xi.is_zero()) {
return Err(Validation("Xi is zero".into()));
}
if !super::secp::point_eq(&super::secp::mul_base(&self.xi), &self.big_xj[self.idx]) {
return Err(Validation("Xi·G != BigXj[idx]".into()));
}
Ok(())
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Signature {
pub r: Vec<u8>,
pub s: Vec<u8>,
pub v: u8,
}