use crate::crypto::{Point, Scalar};
use crate::error::{Error, Result};
use tsslib::frost::Ed25519;
use tsslib::frost::binding::lagrange_coefficient;
use tsslib::frosttss::Key;
pub fn committee_share_ids(key: &Key) -> Vec<Vec<u8>> {
key.ks.iter().map(|k| k.as_be_bytes().to_vec()).collect()
}
pub fn additive_share(key: &Key) -> Result<Scalar> {
let ids = committee_share_ids(key);
let lambda = lagrange_coefficient::<Ed25519>(key.share_id.as_be_bytes(), &ids)
.ok_or_else(|| Error::msg("zanompc: duplicate share id in the signing committee"))?;
Ok(lambda.mul(&key.xi))
}
pub fn partial_key_image(key: &Key, base: &Point) -> Result<Point> {
Ok(base.mul(&additive_share(key)?))
}
pub fn combine_points(parts: &[Point]) -> Point {
parts.iter().fold(Point::identity(), |acc, p| acc.add(p))
}