use crate::log; use async_std::task; use futures::{channel::mpsc, select, Future, FutureExt, SinkExt}; pub use noise_protocol::U8Array; use noise_protocol::DH; pub use noise_rust_crypto::sensitive::Sensitive; #[cfg(target_arch = "wasm32")] pub fn spawn_and_log_error(fut: F) -> task::JoinHandle<()> where F: Future> + 'static, { task::spawn_local(async move { if let Err(e) = fut.await { log!("EXCEPTION {}", e) } }) } #[cfg(target_arch = "wasm32")] pub type ResultSend = std::result::Result>; #[cfg(not(target_arch = "wasm32"))] pub type ResultSend = std::result::Result>; #[cfg(not(target_arch = "wasm32"))] pub fn spawn_and_log_error(fut: F) -> task::JoinHandle<()> where F: Future> + Send + 'static, { task::spawn(async move { if let Err(e) = fut.await { eprintln!("{}", e) } }) } pub type Sender = mpsc::UnboundedSender; pub type Receiver = mpsc::UnboundedReceiver; pub fn gen_keys() -> (Sensitive<[u8; 32]>, [u8; 32]) { let pri = noise_rust_crypto::X25519::genkey(); let publ = noise_rust_crypto::X25519::pubkey(&pri); (pri, publ) }