use std::{marker::Send, sync::Arc}; use async_trait::async_trait; use thiserror::Error; use rand_core::{RngCore, CryptoRng}; use blake2::{digest::{Digest, Update}, Blake2b512}; use frost::{Curve, MultisigKeys}; mod coins; mod wallet; #[cfg(test)] mod tests; pub trait Output: Sized + Clone { type Id; fn id(&self) -> Self::Id; fn amount(&self) -> u64; fn serialize(&self) -> Vec; fn deserialize(reader: &mut R) -> std::io::Result; } #[derive(Clone, Error, Debug)] pub enum CoinError { #[error("failed to connect to coin daemon")] ConnectionError } #[async_trait] pub trait Coin { type Curve: Curve; type Output: Output; type Block; type SignableTransaction; type Address: Send; fn id() -> &'static [u8]; fn confirmations() -> usize; fn max_inputs() -> usize; fn max_outputs() -> usize; async fn get_height(&self) -> Result; async fn get_block(&self, height: usize) -> Result; async fn get_outputs( &self, block: &Self::Block, key: ::G ) -> Vec; async fn prepare_send( &self, keys: Arc>, label: Vec, height: usize, inputs: Vec, payments: &[(Self::Address, u64)] ) -> Result; async fn attempt_send( &self, rng: &mut R, transaction: Self::SignableTransaction, included: &[u16] ) -> Result<(Vec, Vec<::Id>), CoinError>; } // Generate a view key for a given chain in a globally consistent manner regardless of the current // group key // Takes an index, k, for more modern privacy protocols which use multiple view keys // Doesn't run Curve::hash_to_F, instead returning the hash object, due to hash_to_F being a FROST // definition instead of a wide reduction from a hash object pub fn view_key(k: u64) -> Blake2b512 { Blake2b512::new().chain(b"Serai DEX View Key").chain(C::id()).chain(k.to_le_bytes()) }