Skip to content

Commit d9c7bf4

Browse files
feat: add support for parity-scale-codec and scale-info
1 parent b553ff8 commit d9c7bf4

File tree

12 files changed

+73
-24
lines changed

12 files changed

+73
-24
lines changed

Cargo.toml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,22 @@ aes = { version = "0.8", features = ["zeroize"], default-features = false }
2626
ctr = { version = "0.9", features = ["zeroize"], default-features = false }
2727
digest = { version = "0.10", default-features = false }
2828
document-features = "0.2"
29-
frost-core = { version = "2.1", git = "https://github.com/StackOverflowExcept1on/frost", branch = "frost-secp256k1-evm-crates-io-no-std", features = ["internals"], default-features = false }
30-
frost-ed25519 = { version = "2.1", git = "https://github.com/StackOverflowExcept1on/frost", branch = "frost-secp256k1-evm-crates-io-no-std", default-features = false }
31-
frost-ed448 = { version = "2.1", git = "https://github.com/StackOverflowExcept1on/frost", branch = "frost-secp256k1-evm-crates-io-no-std", default-features = false }
32-
frost-p256 = { version = "2.1", git = "https://github.com/StackOverflowExcept1on/frost", branch = "frost-secp256k1-evm-crates-io-no-std", default-features = false }
33-
frost-ristretto255 = { version = "2.1", git = "https://github.com/StackOverflowExcept1on/frost", branch = "frost-secp256k1-evm-crates-io-no-std", default-features = false }
34-
frost-secp256k1 = { version = "2.1", git = "https://github.com/StackOverflowExcept1on/frost", branch = "frost-secp256k1-evm-crates-io-no-std", default-features = false }
35-
frost-secp256k1-evm = { version = "2.1", git = "https://github.com/StackOverflowExcept1on/frost", branch = "frost-secp256k1-evm-crates-io-no-std", default-features = false }
36-
frost-secp256k1-tr = { version = "2.1", git = "https://github.com/StackOverflowExcept1on/frost", branch = "frost-secp256k1-evm-crates-io-no-std", default-features = false }
29+
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 }
30+
frost-ed25519 = { version = "2.1", git = "https://github.com/StackOverflowExcept1on/frost", branch = "frost-secp256k1-evm-crates-io-no-std-codec", default-features = false }
31+
frost-ed448 = { version = "2.1", git = "https://github.com/StackOverflowExcept1on/frost", branch = "frost-secp256k1-evm-crates-io-no-std-codec", default-features = false }
32+
frost-p256 = { version = "2.1", git = "https://github.com/StackOverflowExcept1on/frost", branch = "frost-secp256k1-evm-crates-io-no-std-codec", default-features = false }
33+
frost-ristretto255 = { version = "2.1", git = "https://github.com/StackOverflowExcept1on/frost", branch = "frost-secp256k1-evm-crates-io-no-std-codec", default-features = false }
34+
frost-secp256k1 = { version = "2.1", git = "https://github.com/StackOverflowExcept1on/frost", branch = "frost-secp256k1-evm-crates-io-no-std-codec", default-features = false }
35+
frost-secp256k1-evm = { version = "2.1", git = "https://github.com/StackOverflowExcept1on/frost", branch = "frost-secp256k1-evm-crates-io-no-std-codec", default-features = false }
36+
frost-secp256k1-tr = { version = "2.1", git = "https://github.com/StackOverflowExcept1on/frost", branch = "frost-secp256k1-evm-crates-io-no-std-codec", default-features = false }
3737
hkdf = { version = "0.12", default-features = false }
3838
rand = { version = "0.8", default-features = false }
3939
rand_core = { version = "0.6", default-features = false }
4040
sha2 = { version = "0.10", default-features = false }
4141
sha3 = { version = "0.10", default-features = false }
4242
thiserror = { version = "2.0", default-features = false }
43+
parity-scale-codec = { version = "3.6", default-features = false }
44+
scale-info = { version = "2.11", features = ["derive"], default-features = false }
4345

4446
roast-core = { path = "roast-core", default-features = false }
4547
roast-ed25519 = { path = "roast-ed25519", default-features = false }

roast-core/Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ hkdf.workspace = true
2121
rand = { workspace = true, optional = true }
2222
rand_core.workspace = true
2323
thiserror.workspace = true
24+
parity-scale-codec = { workspace = true, optional = true }
25+
scale-info = { workspace = true, optional = true }
2426

2527
[features]
2628
default = ["serialization", "cheater-detection"]
@@ -29,8 +31,11 @@ default = ["serialization", "cheater-detection"]
2931
## can use `serde` to serialize structs with any encoder that supports
3032
## `serde` (e.g. JSON with `serde_json`).
3133
serde = ["frost-core/serde"]
32-
## Enable a default serialization format. Enables `serde`.
33-
serialization = ["serde", "frost-core/serialization"]
34+
## Enable `parity-scale-codec` and `scale-info` support for types
35+
## that need to be communicated.
36+
codec = ["frost-core/codec", "dep:parity-scale-codec", "dep:scale-info"]
37+
## Enable a default serialization format. Enables `serde` and `codec`.
38+
serialization = ["serde", "codec", "frost-core/serialization"]
3439
## Exposes ciphersuite-generic tests for other crates to use.
3540
test-impl = ["dep:rand"]
3641
## Enable cheater detection.

roast-core/src/coordinator.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,24 @@ use frost_core::{
1010
round2::SignatureShare,
1111
Ciphersuite, Identifier, Signature, SigningPackage,
1212
};
13+
#[cfg(all(feature = "serialization", feature = "codec"))]
14+
use scale_info::{
15+
scale::{self, Decode, Encode},
16+
TypeInfo,
17+
};
1318

1419
type SessionId = u16;
1520

1621
#[derive(Debug)]
22+
#[cfg_attr(all(feature = "serialization", feature = "codec"), derive(Encode, Decode, TypeInfo), codec(crate = scale))] //TODO: fix TypeInfo
1723
struct Session<C: Ciphersuite> {
1824
signing_package: SigningPackage<C>,
1925
signature_shares: BTreeMap<Identifier<C>, SignatureShare<C>>,
2026
}
2127

2228
/// Represents all possible session statuses.
2329
#[derive(Debug)]
30+
#[cfg_attr(all(feature = "serialization", feature = "codec"), derive(Encode, Decode, TypeInfo), codec(crate = scale))] //TODO: fix TypeInfo
2431
pub enum SessionStatus<C: Ciphersuite> {
2532
/// Session still in progress.
2633
InProgress,
@@ -41,6 +48,7 @@ pub enum SessionStatus<C: Ciphersuite> {
4148

4249
/// Represents coordinator.
4350
#[derive(Debug)]
51+
#[cfg_attr(all(feature = "serialization", feature = "codec"), derive(Encode, Decode, TypeInfo), codec(crate = scale))] //TODO: fix TypeInfo
4452
pub struct Coordinator<C: Ciphersuite> {
4553
max_signers: u16,
4654
min_signers: u16,

roast-core/src/dkg.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ use frost_core::{
1818
};
1919
use hkdf::{hmac::SimpleHmac, Hkdf};
2020
use rand_core::{CryptoRng, RngCore};
21+
#[cfg(all(feature = "serialization", feature = "codec"))]
22+
use scale_info::{
23+
scale::{self, Decode, Encode},
24+
TypeInfo,
25+
};
2126

2227
fn diffie_hellman<C: Ciphersuite>(
2328
secret_key: &SigningKey<C>,
@@ -94,6 +99,7 @@ type Round1Package<C> = (round1::Package<C>, VerifyingKey<C>);
9499

95100
/// Represents all possible Distributed Key Generation statuses.
96101
#[derive(Debug)]
102+
#[cfg_attr(all(feature = "serialization", feature = "codec"), derive(Encode, Decode, TypeInfo), codec(crate = scale))]
97103
pub enum DkgStatus {
98104
/// Distributed Key Generation still in progress.
99105
InProgress,
@@ -107,6 +113,7 @@ pub enum DkgStatus {
107113

108114
/// Represents dealer that can be used for Distributed Key Generation.
109115
#[derive(Debug)]
116+
#[cfg_attr(all(feature = "serialization", feature = "codec"), derive(Encode, Decode, TypeInfo), codec(crate = scale))] //TODO: fix TypeInfo
110117
pub struct Dealer<C: Ciphersuite, H: Clone + BlockSizeUser + Digest> {
111118
max_signers: u16,
112119
min_signers: u16,

roast-core/src/error.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
//! Error types.
22
33
use frost_core::{Ciphersuite, Error as FrostErrorType};
4+
#[cfg(all(feature = "serialization", feature = "codec"))]
5+
use scale_info::{
6+
scale::{self, Decode, Encode},
7+
TypeInfo,
8+
};
49
use thiserror::Error;
510

611
/// Represents all possible errors that can occur in FROST protocol.
@@ -47,6 +52,7 @@ pub enum DkgParticipantError<C: Ciphersuite> {
4752

4853
/// Represents all possible errors for which signer can be marked as malicious.
4954
#[derive(Error, Debug, Copy, Clone, Eq, PartialEq)]
55+
#[cfg_attr(all(feature = "serialization", feature = "codec"), derive(Encode, Decode, TypeInfo), codec(crate = scale))]
5056
pub enum MaliciousSignerError {
5157
/// Signer unsolicitedly replied to coordinator.
5258
#[error("Unsolicited reply")]

roast-ed25519/Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ default = ["serialization", "cheater-detection"]
2828
## can use `serde` to serialize structs with any encoder that supports
2929
## `serde` (e.g. JSON with `serde_json`).
3030
serde = ["roast-core/serde"]
31-
## Enable a default serialization format. Enables `serde`.
32-
serialization = ["serde", "roast-core/serialization"]
31+
## Enable `parity-scale-codec` and `scale-info` support for types
32+
## that need to be communicated.
33+
codec = ["roast-core/codec"]
34+
## Enable a default serialization format. Enables `serde` and `codec`.
35+
serialization = ["serde", "codec", "roast-core/serialization"]
3336
## Enable cheater detection.
3437
cheater-detection = ["roast-core/cheater-detection"]

roast-ed448/Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ default = ["serialization", "cheater-detection"]
2828
## can use `serde` to serialize structs with any encoder that supports
2929
## `serde` (e.g. JSON with `serde_json`).
3030
serde = ["roast-core/serde"]
31-
## Enable a default serialization format. Enables `serde`.
32-
serialization = ["serde", "roast-core/serialization"]
31+
## Enable `parity-scale-codec` and `scale-info` support for types
32+
## that need to be communicated.
33+
codec = ["roast-core/codec"]
34+
## Enable a default serialization format. Enables `serde` and `codec`.
35+
serialization = ["serde", "codec", "roast-core/serialization"]
3336
## Enable cheater detection.
3437
cheater-detection = ["roast-core/cheater-detection"]

roast-p256/Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ default = ["serialization", "cheater-detection"]
2828
## can use `serde` to serialize structs with any encoder that supports
2929
## `serde` (e.g. JSON with `serde_json`).
3030
serde = ["roast-core/serde"]
31-
## Enable a default serialization format. Enables `serde`.
32-
serialization = ["serde", "roast-core/serialization"]
31+
## Enable `parity-scale-codec` and `scale-info` support for types
32+
## that need to be communicated.
33+
codec = ["roast-core/codec"]
34+
## Enable a default serialization format. Enables `serde` and `codec`.
35+
serialization = ["serde", "codec", "roast-core/serialization"]
3336
## Enable cheater detection.
3437
cheater-detection = ["roast-core/cheater-detection"]

roast-ristretto255/Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ default = ["serialization", "cheater-detection"]
2828
## can use `serde` to serialize structs with any encoder that supports
2929
## `serde` (e.g. JSON with `serde_json`).
3030
serde = ["roast-core/serde"]
31-
## Enable a default serialization format. Enables `serde`.
32-
serialization = ["serde", "roast-core/serialization"]
31+
## Enable `parity-scale-codec` and `scale-info` support for types
32+
## that need to be communicated.
33+
codec = ["roast-core/codec"]
34+
## Enable a default serialization format. Enables `serde` and `codec`.
35+
serialization = ["serde", "codec", "roast-core/serialization"]
3336
## Enable cheater detection.
3437
cheater-detection = ["roast-core/cheater-detection"]

roast-secp256k1-evm/Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ default = ["serialization", "cheater-detection"]
2828
## can use `serde` to serialize structs with any encoder that supports
2929
## `serde` (e.g. JSON with `serde_json`).
3030
serde = ["roast-core/serde"]
31-
## Enable a default serialization format. Enables `serde`.
32-
serialization = ["serde", "roast-core/serialization"]
31+
## Enable `parity-scale-codec` and `scale-info` support for types
32+
## that need to be communicated.
33+
codec = ["roast-core/codec"]
34+
## Enable a default serialization format. Enables `serde` and `codec`.
35+
serialization = ["serde", "codec", "roast-core/serialization"]
3336
## Enable cheater detection.
3437
cheater-detection = ["roast-core/cheater-detection"]

roast-secp256k1-tr/Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ default = ["serialization", "cheater-detection"]
2828
## can use `serde` to serialize structs with any encoder that supports
2929
## `serde` (e.g. JSON with `serde_json`).
3030
serde = ["roast-core/serde"]
31-
## Enable a default serialization format. Enables `serde`.
32-
serialization = ["serde", "roast-core/serialization"]
31+
## Enable `parity-scale-codec` and `scale-info` support for types
32+
## that need to be communicated.
33+
codec = ["roast-core/codec"]
34+
## Enable a default serialization format. Enables `serde` and `codec`.
35+
serialization = ["serde", "codec", "roast-core/serialization"]
3336
## Enable cheater detection.
3437
cheater-detection = ["roast-core/cheater-detection"]

roast-secp256k1/Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ default = ["serialization", "cheater-detection"]
2828
## can use `serde` to serialize structs with any encoder that supports
2929
## `serde` (e.g. JSON with `serde_json`).
3030
serde = ["roast-core/serde"]
31-
## Enable a default serialization format. Enables `serde`.
32-
serialization = ["serde", "roast-core/serialization"]
31+
## Enable `parity-scale-codec` and `scale-info` support for types
32+
## that need to be communicated.
33+
codec = ["roast-core/codec"]
34+
## Enable a default serialization format. Enables `serde` and `codec`.
35+
serialization = ["serde", "codec", "roast-core/serialization"]
3336
## Enable cheater detection.
3437
cheater-detection = ["roast-core/cheater-detection"]

0 commit comments

Comments
 (0)