From 1a99629a4a1bd6c161dd25d50c05a23ee7e3d679 Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Tue, 7 Mar 2023 03:13:55 -0500 Subject: [PATCH] Add feature-gated serde support for Participant/ThresholdParams These don't have secret data yet sometimes have value to be communicated. --- Cargo.lock | 1 + crypto/dkg/Cargo.toml | 3 +++ crypto/dkg/src/lib.rs | 2 ++ 3 files changed, 6 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index e244b6dc..252ef1a4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1699,6 +1699,7 @@ dependencies = [ "multiexp", "rand_core 0.6.4", "schnorr-signatures", + "serde", "thiserror", "zeroize", ] diff --git a/crypto/dkg/Cargo.toml b/crypto/dkg/Cargo.toml index 00fa973a..22403f7b 100644 --- a/crypto/dkg/Cargo.toml +++ b/crypto/dkg/Cargo.toml @@ -19,6 +19,8 @@ rand_core = "0.6" zeroize = { version = "^1.5", features = ["zeroize_derive"] } +serde = { version = "1", features = ["derive"], optional = true } + transcript = { package = "flexible-transcript", path = "../transcript", version = "0.2", features = ["recommended"] } chacha20 = { version = "0.9", features = ["zeroize"] } @@ -33,4 +35,5 @@ dleq = { path = "../dleq", version = "0.2", features = ["serialize"] } ciphersuite = { path = "../ciphersuite", version = "0.1", features = ["std", "ristretto"] } [features] +serde = ["dep:serde"] tests = [] diff --git a/crypto/dkg/src/lib.rs b/crypto/dkg/src/lib.rs index 4c63104f..47ffc895 100644 --- a/crypto/dkg/src/lib.rs +++ b/crypto/dkg/src/lib.rs @@ -38,6 +38,7 @@ pub mod tests; /// The ID of a participant, defined as a non-zero u16. #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Zeroize)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Participant(pub(crate) u16); impl Participant { pub fn new(i: u16) -> Option { @@ -123,6 +124,7 @@ pub(crate) fn validate_map( /// Parameters for a multisig. // These fields should not be made public as they should be static #[derive(Clone, Copy, PartialEq, Eq, Debug, Zeroize)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct ThresholdParams { /// Participants needed to sign on behalf of the group. t: u16,