Skip to content

Commit

Permalink
feat: add support for parity-scale-codec and scale-info
Browse files Browse the repository at this point in the history
  • Loading branch information
StackOverflowExcept1on committed Feb 2, 2025
1 parent b553ff8 commit d9c7bf4
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 24 deletions.
18 changes: 10 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
9 changes: 7 additions & 2 deletions roast-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions roast-core/src/coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,24 @@ 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<C: Ciphersuite> {
signing_package: SigningPackage<C>,
signature_shares: BTreeMap<Identifier<C>, SignatureShare<C>>,
}

/// 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<C: Ciphersuite> {
/// Session still in progress.
InProgress,
Expand All @@ -41,6 +48,7 @@ pub enum SessionStatus<C: Ciphersuite> {

/// Represents coordinator.
#[derive(Debug)]
#[cfg_attr(all(feature = "serialization", feature = "codec"), derive(Encode, Decode, TypeInfo), codec(crate = scale))] //TODO: fix TypeInfo
pub struct Coordinator<C: Ciphersuite> {
max_signers: u16,
min_signers: u16,
Expand Down
7 changes: 7 additions & 0 deletions roast-core/src/dkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<C: Ciphersuite>(
secret_key: &SigningKey<C>,
Expand Down Expand Up @@ -94,6 +99,7 @@ type Round1Package<C> = (round1::Package<C>, VerifyingKey<C>);

/// 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,
Expand All @@ -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<C: Ciphersuite, H: Clone + BlockSizeUser + Digest> {
max_signers: u16,
min_signers: u16,
Expand Down
6 changes: 6 additions & 0 deletions roast-core/src/error.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -47,6 +52,7 @@ pub enum DkgParticipantError<C: Ciphersuite> {

/// 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")]
Expand Down
7 changes: 5 additions & 2 deletions roast-ed25519/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
7 changes: 5 additions & 2 deletions roast-ed448/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
7 changes: 5 additions & 2 deletions roast-p256/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
7 changes: 5 additions & 2 deletions roast-ristretto255/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
7 changes: 5 additions & 2 deletions roast-secp256k1-evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
7 changes: 5 additions & 2 deletions roast-secp256k1-tr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
7 changes: 5 additions & 2 deletions roast-secp256k1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

0 comments on commit d9c7bf4

Please sign in to comment.