Skip to content

Commit

Permalink
fixup! Merge branch 'namada/tomas/sorted-prefix-iter' (#458)
Browse files Browse the repository at this point in the history
  • Loading branch information
tzemanovic committed Sep 13, 2022
1 parent e85bf62 commit b9406a2
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions shared/src/types/key/secp256k1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::io::{ErrorKind, Write};
use std::str::FromStr;

use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
use data_encoding::HEXLOWER;
#[cfg(feature = "rand")]
use rand::{CryptoRng, RngCore};
use serde::de::{Error, SeqAccess, Visitor};
Expand Down Expand Up @@ -113,15 +114,17 @@ impl Ord for PublicKey {

impl Display for PublicKey {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", hex::encode(&self.0.serialize_compressed()))
write!(f, "{}", HEXLOWER.encode(&self.0.serialize_compressed()))
}
}

impl FromStr for PublicKey {
type Err = ParsePublicKeyError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let vec = hex::decode(s).map_err(ParsePublicKeyError::InvalidHex)?;
let vec = HEXLOWER
.decode(s.as_bytes())
.map_err(ParsePublicKeyError::InvalidHex)?;
BorshDeserialize::try_from_slice(&vec)
.map_err(ParsePublicKeyError::InvalidEncoding)
}
Expand Down Expand Up @@ -226,15 +229,17 @@ impl BorshSchema for SecretKey {

impl Display for SecretKey {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", hex::encode(&self.0.serialize()))
write!(f, "{}", HEXLOWER.encode(&self.0.serialize()))
}
}

impl FromStr for SecretKey {
type Err = ParseSecretKeyError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let vec = hex::decode(s).map_err(ParseSecretKeyError::InvalidHex)?;
let vec = HEXLOWER
.decode(s.as_bytes())
.map_err(ParseSecretKeyError::InvalidHex)?;
BorshDeserialize::try_from_slice(&vec)
.map_err(ParseSecretKeyError::InvalidEncoding)
}
Expand Down

0 comments on commit b9406a2

Please sign in to comment.