1use mpvss_rs::Participant;
6use mpvss_rs::{string_from_secret, string_to_secret};
7
8fn main() {
9 let secret_message = String::from("Hello Sub MPVSS Example.");
10 let mut dealer = Participant::new();
11 dealer.initialize();
12 let mut p1 = Participant::new();
13 let mut p2 = Participant::new();
14 let mut p3 = Participant::new();
15 let mut p4 = Participant::new();
16 p1.initialize();
17 p2.initialize();
18 p3.initialize();
19 p4.initialize();
20
21 let distribute_shares_box = dealer.distribute_secret(
22 &string_to_secret(&secret_message),
23 &vec![
24 p1.publickey.clone(),
25 p2.publickey.clone(),
26 p3.publickey.clone(),
27 p4.publickey.clone(),
28 ],
29 3,
30 );
31
32 assert_eq!(p1.verify_distribution_shares(&distribute_shares_box), true);
33
34 assert_eq!(p2.verify_distribution_shares(&distribute_shares_box), true);
35
36 assert_eq!(p3.verify_distribution_shares(&distribute_shares_box), true);
37
38 assert_eq!(p4.verify_distribution_shares(&distribute_shares_box), true);
39
40 let s1 = p1
42 .extract_secret_share(&distribute_shares_box, &p1.privatekey)
43 .unwrap();
44
45 let s2 = p2
48 .extract_secret_share(&distribute_shares_box, &p2.privatekey)
49 .unwrap();
50 let s3 = p3
51 .extract_secret_share(&distribute_shares_box, &p3.privatekey)
52 .unwrap();
53
54 let s4 = p4
55 .extract_secret_share(&distribute_shares_box, &p4.privatekey)
56 .unwrap();
57
58 assert_eq!(
61 p1.verify_share(&s2, &distribute_shares_box, &p2.publickey),
62 true
63 );
64
65 assert_eq!(
66 p2.verify_share(&s3, &distribute_shares_box, &p3.publickey),
67 true
68 );
69
70 assert_eq!(
71 p3.verify_share(&s1, &distribute_shares_box, &s1.publickey),
72 true
73 );
74
75 assert_eq!(
76 p4.verify_share(&s2, &distribute_shares_box, &s2.publickey),
77 true
78 );
79
80 let share_boxs = [s1.clone(), s2.clone(), s4.clone()];
81 let r1 = p1.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
82 let r2 = p2.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
83 let r3 = p3.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
84 let r4 = p4.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
85
86 let r1_str = string_from_secret(&r1);
87 assert_eq!(secret_message.clone(), r1_str);
88 let r2_str = string_from_secret(&r2);
89 assert_eq!(secret_message.clone(), r2_str);
90 let r3_str = string_from_secret(&r3);
91 assert_eq!(secret_message.clone(), r3_str);
92 let r4_str = string_from_secret(&r4);
93 assert_eq!(secret_message.clone(), r4_str);
94
95 println!("secret message: {}", secret_message);
96 println!("r1 str: {}", r1_str);
97 println!("r2 str: {}", r2_str);
98 println!("r3 str: {}", r3_str);
99 println!("r3 str: {}", r4_str);
100}