From 2c5658732fd4e3a3e9037e9b4e4a216924098af9 Mon Sep 17 00:00:00 2001 From: Denis Varlakov Date: Tue, 13 Feb 2024 08:47:19 +0100 Subject: [PATCH] Change serde implementation for key pair --- src/lib.rs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index aa9b1f9..a025815 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -137,11 +137,6 @@ pub struct ExtendedSecretKey { /// Pair of extended secret and public keys #[derive(Clone, Debug)] -#[cfg_attr( - feature = "serde", - derive(serde::Serialize, serde::Deserialize), - serde(bound = "") -)] pub struct ExtendedKeyPair { public_key: ExtendedPublicKey, secret_key: ExtendedSecretKey, @@ -305,6 +300,27 @@ impl ExtendedKeyPair { } } +#[cfg(feature = "serde")] +impl serde::Serialize for ExtendedKeyPair { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + self.secret_key.serialize(serializer) + } +} + +#[cfg(feature = "serde")] +impl<'de, E: Curve> serde::Deserialize<'de> for ExtendedKeyPair { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + let secret_key = ExtendedSecretKey::::deserialize(deserializer)?; + Ok(secret_key.into()) + } +} + /// Marker for a curve supported by SLIP10 specs and this library /// /// Only implement this trait for the curves that are supported by SLIP10 specs.