2022-04-22 01:36:18 +00:00
|
|
|
#![cfg(feature = "multisig")]
|
|
|
|
|
2022-04-29 01:47:25 +00:00
|
|
|
use rand::{RngCore, rngs::OsRng};
|
2022-04-22 01:36:18 +00:00
|
|
|
|
2022-04-28 16:01:20 +00:00
|
|
|
use monero_serai::{frost::MultisigError, key_image};
|
2022-04-22 01:36:18 +00:00
|
|
|
|
|
|
|
mod frost;
|
2022-04-29 01:47:25 +00:00
|
|
|
use crate::frost::{THRESHOLD, PARTICIPANTS, generate_keys};
|
2022-04-22 01:36:18 +00:00
|
|
|
|
|
|
|
#[test]
|
2022-04-28 16:01:20 +00:00
|
|
|
fn test() -> Result<(), MultisigError> {
|
2022-04-29 01:47:25 +00:00
|
|
|
let (keys, group_private) = generate_keys();
|
2022-04-28 07:31:09 +00:00
|
|
|
let image = key_image::generate(&group_private);
|
2022-04-22 01:36:18 +00:00
|
|
|
|
2022-04-29 01:47:25 +00:00
|
|
|
let mut included = (1 ..= PARTICIPANTS).into_iter().collect::<Vec<usize>>();
|
|
|
|
while included.len() > THRESHOLD {
|
|
|
|
included.swap_remove((OsRng.next_u64() as usize) % included.len());
|
|
|
|
}
|
|
|
|
included.sort();
|
|
|
|
|
2022-04-22 01:36:18 +00:00
|
|
|
let mut packages = vec![];
|
2022-04-29 01:47:25 +00:00
|
|
|
packages.resize(PARTICIPANTS + 1, None);
|
2022-04-22 01:36:18 +00:00
|
|
|
for i in &included {
|
|
|
|
let i = *i;
|
|
|
|
packages[i] = Some(
|
|
|
|
(
|
|
|
|
keys[0].verification_shares()[i].0,
|
|
|
|
key_image::multisig(&mut OsRng, &keys[i - 1], &included)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
for i in included {
|
|
|
|
let mut packages = packages.clone();
|
|
|
|
packages.push(None);
|
|
|
|
let package = packages.swap_remove(i).unwrap().1;
|
|
|
|
assert_eq!(image, package.resolve(packages).unwrap());
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|