Skip to content

Commit

Permalink
Change serde implementation for key pair
Browse files Browse the repository at this point in the history
  • Loading branch information
survived committed Feb 13, 2024
1 parent fe504ac commit 2c56587
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,6 @@ pub struct ExtendedSecretKey<E: Curve> {

/// Pair of extended secret and public keys
#[derive(Clone, Debug)]
#[cfg_attr(
feature = "serde",
derive(serde::Serialize, serde::Deserialize),
serde(bound = "")
)]
pub struct ExtendedKeyPair<E: Curve> {
public_key: ExtendedPublicKey<E>,
secret_key: ExtendedSecretKey<E>,
Expand Down Expand Up @@ -305,6 +300,27 @@ impl<E: Curve> ExtendedKeyPair<E> {
}
}

#[cfg(feature = "serde")]
impl<E: Curve> serde::Serialize for ExtendedKeyPair<E> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
self.secret_key.serialize(serializer)
}
}

#[cfg(feature = "serde")]
impl<'de, E: Curve> serde::Deserialize<'de> for ExtendedKeyPair<E> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let secret_key = ExtendedSecretKey::<E>::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.
Expand Down

0 comments on commit 2c56587

Please sign in to comment.