roast

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

coordinator.rs (3643B)


      1 #![feature(decl_macro)]
      2 
      3 #[macro_use]
      4 extern crate rocket;
      5 
      6 use roast::coordinator::RoastServer;
      7 use rocket::{Rocket, State};
      8 use schnorr_fun::musig::Nonce;
      9 use std::{error::Error, sync::Mutex};
     10 
     11 use schnorr_fun::frost::Frost;
     12 use schnorr_fun::nonce::Deterministic;
     13 use schnorr_fun::{Message, Schnorr};
     14 use sha2::Sha256;
     15 
     16 // Also have optional message here
     17 #[get("/init?<frost_key>")]
     18 pub fn init(roast_db: &State<Mutex<RoastServer<Sha256, Sha256>>>, frost_key: String) {
     19     let mut roast_state = roast_db.lock().expect("got lock");
     20     roast_state.frost_key = serde_json::from_str(&frost_key).expect("read frost key ok");
     21 }
     22 
     23 #[get("/receive_signature?<sig>&<nonce>&<index>")]
     24 pub async fn receive_signature(
     25     roast_db: &State<RoastServer<'_, Sha256, Sha256>>,
     26     sig: Option<String>,
     27     nonce: String,
     28     index: usize,
     29 ) -> String {
     30     let roast_state = roast_db; //.lock().expect("got lock");
     31     let submitted_sig = match sig {
     32         Some(str) => Some(serde_json::from_str(&str).expect("valid sig str")),
     33         None => None,
     34     };
     35     let submitted_nonce = serde_json::from_str(&nonce).expect("valid nonce str");
     36     // let submitted_nonce = match nonce {
     37     //     Some(str) => Some(serde_json::from_str(&str).expect("valid nonce str")),
     38     //     None => None,
     39     // };
     40     roast_state
     41         .receive_signature(index, submitted_sig, submitted_nonce)
     42         .await;
     43 
     44     format!("done")
     45 }
     46 
     47 #[rocket::main]
     48 pub async fn main() -> () {
     49     let res = rocket::build()
     50         .manage(Mutex::new(RoastServer::new(
     51             Frost::new(Schnorr::<Sha256, Deterministic<Sha256>>::new(
     52                 Deterministic::<Sha256>::default(),
     53             )),
     54             None,
     55             Message::plain("test", b"test"),
     56         )))
     57         .mount("/", routes![receive_signature])
     58         .launch()
     59         .await;
     60     ()
     61 }
     62 
     63 //     let frost = Frost::<Sha256, Deterministic<Sha256>>::default();
     64 
     65 //     let message = Message::plain("10 000 emails", b"");
     66 //     // Create a roast server
     67 //     let roast_coordinator =
     68 //         roast_coordinator::RoastServer::new(frost.clone(), frost_keys[0].clone(), message);
     69 
     70 // let roast_signer1 = roast_signer::RoastClient::start(
     71 //     roast_coordinator,
     72 //     frost.clone(),
     73 //     frost_keys[0].clone(),
     74 //     0,
     75 //     secret_shares[0].clone(),
     76 //     [0].as_slice(),
     77 //     message,
     78 // )
     79 // .await;
     80 
     81 // let roast_signer1.
     82 
     83 // We need to somehow set some general methods of communication for roast signers and clients
     84 // Rocket API probably not the most basic? Would be cool...
     85 //
     86 
     87 // let roast_signer2 = roast_signer::RoastClient::start(
     88 //     roast_coordinator,
     89 //     frost.clone(),
     90 //     frost_keys[0].clone(),
     91 //     0,
     92 //     secret_shares[0].clone(),
     93 //     [0].as_slice(),
     94 //     message,
     95 // );
     96 
     97 
     98 
     99 // OLD HTTP TRASH
    100 //
    101 //
    102 // HTTP call roast_server receive
    103 // let (combined_sig, nonce_set) =
    104 // let request_url = roast_server.clone()
    105 //     + "/init?"
    106 //     + &serde_json::to_string(&frost_key).expect("valid serialization");
    107 // let response = reqwest::get(&request_url).await.expect("valid request");
    108 // dbg!(response);
    109 
    110 // roast_server
    111 //     .receive_signature(my_index, None, initial_nonce.public)
    112 //     .await;
    113 
    114 // match combined_sig {
    115 //     Some(_) => {
    116 //         println!("got combined sig!");
    117 //     }
    118 //     None => {
    119 //         // println!("Sent partial signature {} to roast..", i)
    120 //     }
    121 // };
    122 // match nonce_set {
    123 //     Some(nonces) => {
    124 //         println!("Got nonces {:?}", nonces);
    125 //     }
    126 //     None => println!("No new nonces!?"),
    127 // };
    128 
    129 // let mut my_nonces = HashMap::new();
    130 // my_nonces.insert(0 as usize, initial_nonce);
    131 
    132 // pub async fn sign