diff --git a/src/crypto/keypair.rs b/src/crypto/keypair.rs index ef4761a8b..5c7cd0169 100644 --- a/src/crypto/keypair.rs +++ b/src/crypto/keypair.rs @@ -1,4 +1,4 @@ -use std::{convert::TryFrom, io}; +use std::{convert::TryFrom, io, str::FromStr}; use halo2_gadgets::ecc::chip::FixedPoint; use pasta_curves::{ @@ -76,8 +76,19 @@ impl PublicKey { self.0.to_bytes() } + pub fn from_bytes(bytes: &[u8; 32]) -> Result { + match pallas::Point::from_bytes(bytes).into() { + Some(k) => Ok(Self(k)), + None => Err(Error::PublicKeyFromBytes), + } + } +} + +impl FromStr for PublicKey { + type Err = crate::Error; + /// Tries to create a `PublicKey` instance from a base58 encoded string. - pub fn from_str(encoded: &str) -> Result { + fn from_str(encoded: &str) -> std::result::Result { let decoded = bs58::decode(encoded).into_vec()?; if decoded.len() != 32 { return Err(Error::PublicKeyFromStr) @@ -85,13 +96,6 @@ impl PublicKey { Self::from_bytes(&decoded.try_into().unwrap()) } - - pub fn from_bytes(bytes: &[u8; 32]) -> Result { - match pallas::Point::from_bytes(bytes).into() { - Some(k) => Ok(Self(k)), - None => Err(Error::PublicKeyFromBytes), - } - } } impl TryFrom
for PublicKey {