diff --git a/Cargo.toml b/Cargo.toml index 5d1e0e4..6f7db4f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,20 +26,22 @@ aes = { version = "0.8", features = ["zeroize"], default-features = false } ctr = { version = "0.9", features = ["zeroize"], default-features = false } digest = { version = "0.10", default-features = false } document-features = "0.2" -frost-core = { version = "2.1", git = "https://github.com/StackOverflowExcept1on/frost", branch = "frost-secp256k1-evm-crates-io-no-std", features = ["internals"], default-features = false } -frost-ed25519 = { version = "2.1", git = "https://github.com/StackOverflowExcept1on/frost", branch = "frost-secp256k1-evm-crates-io-no-std", default-features = false } -frost-ed448 = { version = "2.1", git = "https://github.com/StackOverflowExcept1on/frost", branch = "frost-secp256k1-evm-crates-io-no-std", default-features = false } -frost-p256 = { version = "2.1", git = "https://github.com/StackOverflowExcept1on/frost", branch = "frost-secp256k1-evm-crates-io-no-std", default-features = false } -frost-ristretto255 = { version = "2.1", git = "https://github.com/StackOverflowExcept1on/frost", branch = "frost-secp256k1-evm-crates-io-no-std", default-features = false } -frost-secp256k1 = { version = "2.1", git = "https://github.com/StackOverflowExcept1on/frost", branch = "frost-secp256k1-evm-crates-io-no-std", default-features = false } -frost-secp256k1-evm = { version = "2.1", git = "https://github.com/StackOverflowExcept1on/frost", branch = "frost-secp256k1-evm-crates-io-no-std", default-features = false } -frost-secp256k1-tr = { version = "2.1", git = "https://github.com/StackOverflowExcept1on/frost", branch = "frost-secp256k1-evm-crates-io-no-std", default-features = false } +frost-core = { version = "2.1", git = "https://github.com/StackOverflowExcept1on/frost", branch = "frost-secp256k1-evm-crates-io-no-std-codec", features = ["internals"], default-features = false } +frost-ed25519 = { version = "2.1", git = "https://github.com/StackOverflowExcept1on/frost", branch = "frost-secp256k1-evm-crates-io-no-std-codec", default-features = false } +frost-ed448 = { version = "2.1", git = "https://github.com/StackOverflowExcept1on/frost", branch = "frost-secp256k1-evm-crates-io-no-std-codec", default-features = false } +frost-p256 = { version = "2.1", git = "https://github.com/StackOverflowExcept1on/frost", branch = "frost-secp256k1-evm-crates-io-no-std-codec", default-features = false } +frost-ristretto255 = { version = "2.1", git = "https://github.com/StackOverflowExcept1on/frost", branch = "frost-secp256k1-evm-crates-io-no-std-codec", default-features = false } +frost-secp256k1 = { version = "2.1", git = "https://github.com/StackOverflowExcept1on/frost", branch = "frost-secp256k1-evm-crates-io-no-std-codec", default-features = false } +frost-secp256k1-evm = { version = "2.1", git = "https://github.com/StackOverflowExcept1on/frost", branch = "frost-secp256k1-evm-crates-io-no-std-codec", default-features = false } +frost-secp256k1-tr = { version = "2.1", git = "https://github.com/StackOverflowExcept1on/frost", branch = "frost-secp256k1-evm-crates-io-no-std-codec", default-features = false } hkdf = { version = "0.12", default-features = false } rand = { version = "0.8", default-features = false } rand_core = { version = "0.6", default-features = false } sha2 = { version = "0.10", default-features = false } sha3 = { version = "0.10", default-features = false } thiserror = { version = "2.0", default-features = false } +parity-scale-codec = { version = "3.6", default-features = false } +scale-info = { version = "2.11", features = ["derive"], default-features = false } roast-core = { path = "roast-core", default-features = false } roast-ed25519 = { path = "roast-ed25519", default-features = false } diff --git a/roast-core/Cargo.toml b/roast-core/Cargo.toml index e4da64e..00ce989 100644 --- a/roast-core/Cargo.toml +++ b/roast-core/Cargo.toml @@ -21,6 +21,8 @@ hkdf.workspace = true rand = { workspace = true, optional = true } rand_core.workspace = true thiserror.workspace = true +parity-scale-codec = { workspace = true, optional = true } +scale-info = { workspace = true, optional = true } [features] default = ["serialization", "cheater-detection"] @@ -29,8 +31,11 @@ default = ["serialization", "cheater-detection"] ## can use `serde` to serialize structs with any encoder that supports ## `serde` (e.g. JSON with `serde_json`). serde = ["frost-core/serde"] -## Enable a default serialization format. Enables `serde`. -serialization = ["serde", "frost-core/serialization"] +## Enable `parity-scale-codec` and `scale-info` support for types +## that need to be communicated. +codec = ["frost-core/codec", "dep:parity-scale-codec", "dep:scale-info"] +## Enable a default serialization format. Enables `serde` and `codec`. +serialization = ["serde", "codec", "frost-core/serialization"] ## Exposes ciphersuite-generic tests for other crates to use. test-impl = ["dep:rand"] ## Enable cheater detection. diff --git a/roast-core/src/coordinator.rs b/roast-core/src/coordinator.rs index 8d9a512..f23bb72 100644 --- a/roast-core/src/coordinator.rs +++ b/roast-core/src/coordinator.rs @@ -10,10 +10,16 @@ use frost_core::{ round2::SignatureShare, Ciphersuite, Identifier, Signature, SigningPackage, }; +#[cfg(all(feature = "serialization", feature = "codec"))] +use scale_info::{ + scale::{self, Decode, Encode}, + TypeInfo, +}; type SessionId = u16; #[derive(Debug)] +#[cfg_attr(all(feature = "serialization", feature = "codec"), derive(Encode, Decode, TypeInfo), codec(crate = scale))] //TODO: fix TypeInfo struct Session { signing_package: SigningPackage, signature_shares: BTreeMap, SignatureShare>, @@ -21,6 +27,7 @@ struct Session { /// Represents all possible session statuses. #[derive(Debug)] +#[cfg_attr(all(feature = "serialization", feature = "codec"), derive(Encode, Decode, TypeInfo), codec(crate = scale))] //TODO: fix TypeInfo pub enum SessionStatus { /// Session still in progress. InProgress, @@ -41,6 +48,7 @@ pub enum SessionStatus { /// Represents coordinator. #[derive(Debug)] +#[cfg_attr(all(feature = "serialization", feature = "codec"), derive(Encode, Decode, TypeInfo), codec(crate = scale))] //TODO: fix TypeInfo pub struct Coordinator { max_signers: u16, min_signers: u16, diff --git a/roast-core/src/dkg.rs b/roast-core/src/dkg.rs index 1a68a41..459caa0 100644 --- a/roast-core/src/dkg.rs +++ b/roast-core/src/dkg.rs @@ -18,6 +18,11 @@ use frost_core::{ }; use hkdf::{hmac::SimpleHmac, Hkdf}; use rand_core::{CryptoRng, RngCore}; +#[cfg(all(feature = "serialization", feature = "codec"))] +use scale_info::{ + scale::{self, Decode, Encode}, + TypeInfo, +}; fn diffie_hellman( secret_key: &SigningKey, @@ -94,6 +99,7 @@ type Round1Package = (round1::Package, VerifyingKey); /// Represents all possible Distributed Key Generation statuses. #[derive(Debug)] +#[cfg_attr(all(feature = "serialization", feature = "codec"), derive(Encode, Decode, TypeInfo), codec(crate = scale))] pub enum DkgStatus { /// Distributed Key Generation still in progress. InProgress, @@ -107,6 +113,7 @@ pub enum DkgStatus { /// Represents dealer that can be used for Distributed Key Generation. #[derive(Debug)] +#[cfg_attr(all(feature = "serialization", feature = "codec"), derive(Encode, Decode, TypeInfo), codec(crate = scale))] //TODO: fix TypeInfo pub struct Dealer { max_signers: u16, min_signers: u16, diff --git a/roast-core/src/error.rs b/roast-core/src/error.rs index f859ae4..3d13796 100644 --- a/roast-core/src/error.rs +++ b/roast-core/src/error.rs @@ -1,6 +1,11 @@ //! Error types. use frost_core::{Ciphersuite, Error as FrostErrorType}; +#[cfg(all(feature = "serialization", feature = "codec"))] +use scale_info::{ + scale::{self, Decode, Encode}, + TypeInfo, +}; use thiserror::Error; /// Represents all possible errors that can occur in FROST protocol. @@ -47,6 +52,7 @@ pub enum DkgParticipantError { /// Represents all possible errors for which signer can be marked as malicious. #[derive(Error, Debug, Copy, Clone, Eq, PartialEq)] +#[cfg_attr(all(feature = "serialization", feature = "codec"), derive(Encode, Decode, TypeInfo), codec(crate = scale))] pub enum MaliciousSignerError { /// Signer unsolicitedly replied to coordinator. #[error("Unsolicited reply")] diff --git a/roast-ed25519/Cargo.toml b/roast-ed25519/Cargo.toml index 8dfcbf3..723f453 100644 --- a/roast-ed25519/Cargo.toml +++ b/roast-ed25519/Cargo.toml @@ -28,7 +28,10 @@ default = ["serialization", "cheater-detection"] ## can use `serde` to serialize structs with any encoder that supports ## `serde` (e.g. JSON with `serde_json`). serde = ["roast-core/serde"] -## Enable a default serialization format. Enables `serde`. -serialization = ["serde", "roast-core/serialization"] +## Enable `parity-scale-codec` and `scale-info` support for types +## that need to be communicated. +codec = ["roast-core/codec"] +## Enable a default serialization format. Enables `serde` and `codec`. +serialization = ["serde", "codec", "roast-core/serialization"] ## Enable cheater detection. cheater-detection = ["roast-core/cheater-detection"] diff --git a/roast-ed448/Cargo.toml b/roast-ed448/Cargo.toml index 2f8e327..23a2f98 100644 --- a/roast-ed448/Cargo.toml +++ b/roast-ed448/Cargo.toml @@ -28,7 +28,10 @@ default = ["serialization", "cheater-detection"] ## can use `serde` to serialize structs with any encoder that supports ## `serde` (e.g. JSON with `serde_json`). serde = ["roast-core/serde"] -## Enable a default serialization format. Enables `serde`. -serialization = ["serde", "roast-core/serialization"] +## Enable `parity-scale-codec` and `scale-info` support for types +## that need to be communicated. +codec = ["roast-core/codec"] +## Enable a default serialization format. Enables `serde` and `codec`. +serialization = ["serde", "codec", "roast-core/serialization"] ## Enable cheater detection. cheater-detection = ["roast-core/cheater-detection"] diff --git a/roast-p256/Cargo.toml b/roast-p256/Cargo.toml index 76d7efd..33e7756 100644 --- a/roast-p256/Cargo.toml +++ b/roast-p256/Cargo.toml @@ -28,7 +28,10 @@ default = ["serialization", "cheater-detection"] ## can use `serde` to serialize structs with any encoder that supports ## `serde` (e.g. JSON with `serde_json`). serde = ["roast-core/serde"] -## Enable a default serialization format. Enables `serde`. -serialization = ["serde", "roast-core/serialization"] +## Enable `parity-scale-codec` and `scale-info` support for types +## that need to be communicated. +codec = ["roast-core/codec"] +## Enable a default serialization format. Enables `serde` and `codec`. +serialization = ["serde", "codec", "roast-core/serialization"] ## Enable cheater detection. cheater-detection = ["roast-core/cheater-detection"] diff --git a/roast-ristretto255/Cargo.toml b/roast-ristretto255/Cargo.toml index c4048f2..3601b4a 100644 --- a/roast-ristretto255/Cargo.toml +++ b/roast-ristretto255/Cargo.toml @@ -28,7 +28,10 @@ default = ["serialization", "cheater-detection"] ## can use `serde` to serialize structs with any encoder that supports ## `serde` (e.g. JSON with `serde_json`). serde = ["roast-core/serde"] -## Enable a default serialization format. Enables `serde`. -serialization = ["serde", "roast-core/serialization"] +## Enable `parity-scale-codec` and `scale-info` support for types +## that need to be communicated. +codec = ["roast-core/codec"] +## Enable a default serialization format. Enables `serde` and `codec`. +serialization = ["serde", "codec", "roast-core/serialization"] ## Enable cheater detection. cheater-detection = ["roast-core/cheater-detection"] diff --git a/roast-secp256k1-evm/Cargo.toml b/roast-secp256k1-evm/Cargo.toml index afe64f1..71ce51f 100644 --- a/roast-secp256k1-evm/Cargo.toml +++ b/roast-secp256k1-evm/Cargo.toml @@ -28,7 +28,10 @@ default = ["serialization", "cheater-detection"] ## can use `serde` to serialize structs with any encoder that supports ## `serde` (e.g. JSON with `serde_json`). serde = ["roast-core/serde"] -## Enable a default serialization format. Enables `serde`. -serialization = ["serde", "roast-core/serialization"] +## Enable `parity-scale-codec` and `scale-info` support for types +## that need to be communicated. +codec = ["roast-core/codec"] +## Enable a default serialization format. Enables `serde` and `codec`. +serialization = ["serde", "codec", "roast-core/serialization"] ## Enable cheater detection. cheater-detection = ["roast-core/cheater-detection"] diff --git a/roast-secp256k1-tr/Cargo.toml b/roast-secp256k1-tr/Cargo.toml index 5e54c7c..05ad667 100644 --- a/roast-secp256k1-tr/Cargo.toml +++ b/roast-secp256k1-tr/Cargo.toml @@ -28,7 +28,10 @@ default = ["serialization", "cheater-detection"] ## can use `serde` to serialize structs with any encoder that supports ## `serde` (e.g. JSON with `serde_json`). serde = ["roast-core/serde"] -## Enable a default serialization format. Enables `serde`. -serialization = ["serde", "roast-core/serialization"] +## Enable `parity-scale-codec` and `scale-info` support for types +## that need to be communicated. +codec = ["roast-core/codec"] +## Enable a default serialization format. Enables `serde` and `codec`. +serialization = ["serde", "codec", "roast-core/serialization"] ## Enable cheater detection. cheater-detection = ["roast-core/cheater-detection"] diff --git a/roast-secp256k1/Cargo.toml b/roast-secp256k1/Cargo.toml index 163dcd5..b542ec1 100644 --- a/roast-secp256k1/Cargo.toml +++ b/roast-secp256k1/Cargo.toml @@ -28,7 +28,10 @@ default = ["serialization", "cheater-detection"] ## can use `serde` to serialize structs with any encoder that supports ## `serde` (e.g. JSON with `serde_json`). serde = ["roast-core/serde"] -## Enable a default serialization format. Enables `serde`. -serialization = ["serde", "roast-core/serialization"] +## Enable `parity-scale-codec` and `scale-info` support for types +## that need to be communicated. +codec = ["roast-core/codec"] +## Enable a default serialization format. Enables `serde` and `codec`. +serialization = ["serde", "codec", "roast-core/serialization"] ## Enable cheater detection. cheater-detection = ["roast-core/cheater-detection"]