diff --git a/src/crypto/keypair.rs b/src/crypto/keypair.rs index dc3602f5f..1e5454b30 100644 --- a/src/crypto/keypair.rs +++ b/src/crypto/keypair.rs @@ -12,7 +12,7 @@ use rand::RngCore; use crate::{ crypto::{address::Address, constants::NullifierK, util::mod_r_p}, - util::serial::{Decodable, Encodable, ReadExt, WriteExt}, + util::serial::{Decodable, Encodable, ReadExt, SerialDecodable, SerialEncodable, WriteExt}, Error, Result, }; @@ -36,7 +36,7 @@ impl Keypair { } } -#[derive(Copy, Clone, PartialEq, Debug)] +#[derive(Copy, Clone, PartialEq, Debug, SerialDecodable, SerialEncodable)] pub struct SecretKey(pub pallas::Base); impl SecretKey { @@ -57,7 +57,7 @@ impl SecretKey { } } -#[derive(Copy, Clone, PartialEq, Debug)] +#[derive(Copy, Clone, PartialEq, Debug, SerialDecodable, SerialEncodable)] pub struct PublicKey(pub pallas::Point); impl PublicKey { @@ -153,46 +153,6 @@ impl Decodable for pallas::Point { } } -impl Encodable for SecretKey { - fn encode(&self, mut s: S) -> Result { - s.write_slice(&self.0.to_repr()[..])?; - Ok(32) - } -} - -impl Decodable for SecretKey { - fn decode(mut d: D) -> Result { - let mut bytes = [0u8; 32]; - d.read_slice(&mut bytes)?; - let result = pallas::Base::from_repr(bytes); - if result.is_some().into() { - Ok(SecretKey(result.unwrap())) - } else { - Err(Error::BadOperationType) - } - } -} - -impl Encodable for PublicKey { - fn encode(&self, mut s: S) -> Result { - s.write_slice(&self.0.to_bytes()[..])?; - Ok(32) - } -} - -impl Decodable for PublicKey { - fn decode(mut d: D) -> Result { - let mut bytes = [0u8; 32]; - d.read_slice(&mut bytes)?; - let result = pallas::Point::from_bytes(&bytes); - if result.is_some().into() { - Ok(PublicKey(result.unwrap())) - } else { - Err(Error::BadOperationType) - } - } -} - #[cfg(feature = "serde")] impl serde::Serialize for SecretKey { fn serialize(&self, serializer: S) -> std::result::Result