From ec7d8ac67b59533b1f5dc4930cd67073b916444e Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Sun, 16 Oct 2022 13:11:32 -0400 Subject: [PATCH] Remove coin crate Effective reversion of past few commits by request. --- Cargo.lock | 23 +++------- coin/Cargo.toml | 47 -------------------- coin/LICENSE | 21 --------- coin/README.md | 4 -- coin/src/utils.rs | 11 ----- processor/Cargo.toml | 11 +++-- coin/src/lib.rs => processor/src/coin/mod.rs | 10 ++--- {coin/src => processor/src/coin}/monero.rs | 15 ++++--- processor/src/lib.rs | 14 ++++-- 9 files changed, 36 insertions(+), 120 deletions(-) delete mode 100644 coin/Cargo.toml delete mode 100644 coin/LICENSE delete mode 100644 coin/README.md delete mode 100644 coin/src/utils.rs rename coin/src/lib.rs => processor/src/coin/mod.rs (92%) rename {coin/src => processor/src/coin}/monero.rs (96%) diff --git a/Cargo.lock b/Cargo.lock index 030b4d15..5806cb4b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7497,23 +7497,6 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "930c0acf610d3fdb5e2ab6213019aaa04e227ebe9547b0649ba599b16d788bd7" -[[package]] -name = "serai-coin" -version = "0.1.0" -dependencies = [ - "async-trait", - "curve25519-dalek 3.2.0", - "dalek-ff-group", - "flexible-transcript", - "group", - "modular-frost", - "monero-serai", - "rand_core 0.6.4", - "serde", - "serde_json", - "thiserror", -] - [[package]] name = "serai-consensus" version = "0.1.0" @@ -7604,13 +7587,17 @@ name = "serai-processor" version = "0.1.0" dependencies = [ "async-trait", + "curve25519-dalek 3.2.0", + "dalek-ff-group", "flexible-transcript", "futures", "group", "hex", "modular-frost", + "monero-serai", "rand_core 0.6.4", - "serai-coin", + "serde", + "serde_json", "thiserror", "tokio", ] diff --git a/coin/Cargo.toml b/coin/Cargo.toml deleted file mode 100644 index f5f07c60..00000000 --- a/coin/Cargo.toml +++ /dev/null @@ -1,47 +0,0 @@ -[package] -name = "serai-coin" -version = "0.1.0" -description = "An abstract interface representing a coin, along with implementations for various coins." -license = "MIT" -repository = "https://github.com/serai-dex/serai/tree/develop/coin" -authors = ["Luke Parker "] -keywords = [] -edition = "2021" -publish = false - -[package.metadata.docs.rs] -all-features = true -rustdoc-args = ["--cfg", "docsrs"] - -[dependencies] -async-trait = "0.1" -thiserror = "1" - -curve25519-dalek = { version = "3", features = ["std"] } - -transcript = { package = "flexible-transcript", path = "../crypto/transcript", features = ["recommended"] } -dalek-ff-group = { path = "../crypto/dalek-ff-group" } -frost = { package = "modular-frost", path = "../crypto/frost", features = ["secp256k1", "ed25519"] } - -monero-serai = { path = "../coins/monero", features = ["multisig"] } - -# Test Dependencies -rand_core = { version = "0.6", optional = true } - -group = { version = "0.12", optional = true } - -serde = { version = "1.0", features = ["derive"], optional = true } -serde_json = { version = "1.0", optional = true } - -[dev-dependencies] -rand_core = "0.6" - -group = "0.12" - -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" - -[features] -monero = [] -monero_test = ["rand_core", "group", "serde", "serde_json"] -test = ["monero_test"] diff --git a/coin/LICENSE b/coin/LICENSE deleted file mode 100644 index f05b748b..00000000 --- a/coin/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022 Luke Parker - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/coin/README.md b/coin/README.md deleted file mode 100644 index 7f055d5f..00000000 --- a/coin/README.md +++ /dev/null @@ -1,4 +0,0 @@ -# Serai Coin - -An abstract interface representing a coin, along with implementations for -various coins. diff --git a/coin/src/utils.rs b/coin/src/utils.rs deleted file mode 100644 index 3370f59c..00000000 --- a/coin/src/utils.rs +++ /dev/null @@ -1,11 +0,0 @@ -use frost::curve::Curve; - -use crate::Coin; - -// Generate a static additional key for a given chain in a globally consistent manner -// Doesn't consider the current group key to increase the simplicity of verifying Serai's status -// Takes an index, k, to support protocols which use multiple secondary keys -// Presumably a view key -pub(crate) fn additional_key(k: u64) -> ::F { - C::Curve::hash_to_F(b"Serai DEX Additional Key", &[C::ID, &k.to_le_bytes()].concat()) -} diff --git a/processor/Cargo.toml b/processor/Cargo.toml index 2f01da0a..25eafd5a 100644 --- a/processor/Cargo.toml +++ b/processor/Cargo.toml @@ -20,17 +20,22 @@ thiserror = "1" group = "0.12" +curve25519-dalek = { version = "3", features = ["std"] } + transcript = { package = "flexible-transcript", path = "../crypto/transcript", features = ["recommended"] } +dalek-ff-group = { path = "../crypto/dalek-ff-group" } frost = { package = "modular-frost", path = "../crypto/frost", features = ["ed25519"] } -serai-coin = { path = "../coin", features = ["monero"] } +monero-serai = { path = "../coins/monero", features = ["multisig"] } [dev-dependencies] +rand_core = "0.6" + hex = "0.4" +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" futures = "0.3" tokio = { version = "1", features = ["full"] } frost = { package = "modular-frost", path = "../crypto/frost", features = ["ed25519", "tests"] } - -serai-coin = { path = "../coin", features = ["monero", "test"] } diff --git a/coin/src/lib.rs b/processor/src/coin/mod.rs similarity index 92% rename from coin/src/lib.rs rename to processor/src/coin/mod.rs index 0fa9c55d..6420faff 100644 --- a/coin/src/lib.rs +++ b/processor/src/coin/mod.rs @@ -6,11 +6,7 @@ use thiserror::Error; use transcript::RecommendedTranscript; use frost::{curve::Curve, FrostKeys, sign::PreprocessMachine}; -pub(crate) mod utils; - -#[cfg(feature = "monero")] pub mod monero; -#[cfg(feature = "monero")] pub use self::monero::Monero; #[derive(Clone, Error, Debug)] @@ -83,12 +79,12 @@ pub trait Coin { tx: &Self::Transaction, ) -> Result<(Vec, Vec<::Id>), CoinError>; - #[cfg(any(test, feature = "test"))] + #[cfg(test)] async fn get_fee(&self) -> Self::Fee; - #[cfg(any(test, feature = "test"))] + #[cfg(test)] async fn mine_block(&self); - #[cfg(any(test, feature = "test"))] + #[cfg(test)] async fn test_send(&self, key: Self::Address); } diff --git a/coin/src/monero.rs b/processor/src/coin/monero.rs similarity index 96% rename from coin/src/monero.rs rename to processor/src/coin/monero.rs index fde20cb6..6643c466 100644 --- a/coin/src/monero.rs +++ b/processor/src/coin/monero.rs @@ -17,7 +17,10 @@ use monero_serai::{ }, }; -use crate::{CoinError, Output as OutputTrait, Coin, utils::additional_key}; +use crate::{ + additional_key, + coin::{CoinError, Output as OutputTrait, Coin}, +}; #[derive(Clone, Debug)] pub struct Output(SpendableOutput); @@ -74,7 +77,7 @@ impl Monero { Scanner::from_view(ViewPair::new(spend.0, self.view), Network::Mainnet, None) } - #[cfg(any(test, feature = "test"))] + #[cfg(test)] fn empty_scanner() -> Scanner { use group::Group; Scanner::from_view( @@ -84,7 +87,7 @@ impl Monero { ) } - #[cfg(any(test, feature = "test"))] + #[cfg(test)] fn empty_address() -> Address { Self::empty_scanner().address() } @@ -206,12 +209,12 @@ impl Coin for Monero { Ok((tx.hash().to_vec(), tx.prefix.outputs.iter().map(|output| output.key.to_bytes()).collect())) } - #[cfg(any(test, feature = "test"))] + #[cfg(test)] async fn get_fee(&self) -> Self::Fee { self.rpc.get_fee().await.unwrap() } - #[cfg(any(test, feature = "test"))] + #[cfg(test)] async fn mine_block(&self) { #[derive(serde::Deserialize, Debug)] struct EmptyResponse {} @@ -231,7 +234,7 @@ impl Coin for Monero { .unwrap(); } - #[cfg(any(test, feature = "test"))] + #[cfg(test)] async fn test_send(&self, address: Self::Address) { use rand_core::OsRng; diff --git a/processor/src/lib.rs b/processor/src/lib.rs index 1a605e77..45583dc2 100644 --- a/processor/src/lib.rs +++ b/processor/src/lib.rs @@ -3,10 +3,10 @@ use std::{marker::Send, io::Cursor, collections::HashMap}; use async_trait::async_trait; use thiserror::Error; -use frost::FrostError; +use frost::{curve::Curve, FrostError}; -pub use serai_coin as coin; -use coin::CoinError; +mod coin; +use coin::{CoinError, Coin}; mod wallet; @@ -30,3 +30,11 @@ pub enum SignError { #[error("network had an error {0}")] NetworkError(NetworkError), } + +// Generate a static additional key for a given chain in a globally consistent manner +// Doesn't consider the current group key to increase the simplicity of verifying Serai's status +// Takes an index, k, to support protocols which use multiple secondary keys +// Presumably a view key +pub(crate) fn additional_key(k: u64) -> ::F { + C::Curve::hash_to_F(b"Serai DEX Additional Key", &[C::ID, &k.to_le_bytes()].concat()) +}