client.rs (1706B)
1 #![feature(decl_macro)] 2 3 #[macro_use] 4 extern crate rocket; 5 use roast_signer::client::RoastClient; 6 use roast_signer::frost; 7 8 use rocket::State; 9 use schnorr_fun::{ 10 frost::{Frost, XOnlyFrostKey}, 11 nonce::Deterministic, 12 Message, Schnorr, 13 }; 14 use secp256kfun::Scalar; 15 use sha2::Sha256; 16 use std::{error::Error, sync::Mutex}; 17 18 #[get("/sign?<nonce_set>")] 19 pub fn sign<'a>( 20 signer_db: &State<Mutex<RoastClient<'a, Sha256, Deterministic<Sha256>>>>, 21 nonce_set: String, 22 ) -> () { 23 } 24 25 #[rocket::main] 26 // Here we need to spawn n_parties of rockets under different ports and launch? 27 async fn main() -> Result<(), Box<dyn Error>> { 28 let message = Message::plain("test", b"test"); 29 let (secret_shares, frost_keys) = frost::frost_keygen(3, 5); 30 frost_keys 31 .iter() 32 .zip(secret_shares) 33 .enumerate() 34 .map(|(i, (frost_key, secret_share))| { 35 create_roast_client(frost_key.clone(), i, secret_share, [0].as_slice(), message) 36 }); 37 Ok(()) 38 } 39 40 fn create_roast_client<'a>( 41 frost_key: XOnlyFrostKey, 42 my_index: usize, 43 secret_share: Scalar, 44 initial_nonce_sid: &[u8], 45 message: Message<'a>, 46 ) -> Result<(), Box<dyn Error>> { 47 rocket::build() 48 .manage(Mutex::new(RoastClient::start( 49 "127.0.0.1:510".to_string(), 50 Frost::new(Schnorr::<Sha256, Deterministic<Sha256>>::new( 51 Deterministic::<Sha256>::default(), 52 )), 53 frost_key, 54 my_index, 55 secret_share, 56 initial_nonce_sid, 57 message, 58 ))) 59 .mount( 60 "/", 61 routes![ 62 sign, //post 63 ], 64 ) 65 .launch(); 66 Ok(()) 67 }