From 6bf6ba337dc96b8063872eeb5a1e23689ab30d1c Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Tue, 11 Jun 2019 18:00:05 +1000 Subject: [PATCH] bls: as_hex_string for aggregate signatures/pubkeys --- eth2/utils/bls/src/aggregate_public_key.rs | 7 +++++++ eth2/utils/bls/src/aggregate_signature.rs | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/eth2/utils/bls/src/aggregate_public_key.rs b/eth2/utils/bls/src/aggregate_public_key.rs index d36477d760..2980462486 100644 --- a/eth2/utils/bls/src/aggregate_public_key.rs +++ b/eth2/utils/bls/src/aggregate_public_key.rs @@ -1,5 +1,6 @@ use super::PublicKey; use milagro_bls::AggregatePublicKey as RawAggregatePublicKey; +use serde_hex::encode as hex_encode; /// A BLS aggregate public key. /// @@ -21,4 +22,10 @@ impl AggregatePublicKey { pub fn as_raw(&self) -> &RawAggregatePublicKey { &self.0 } + + /// Return a hex string representation of this key's bytes. + #[cfg(test)] + pub fn as_hex_string(&self) -> String { + hex_encode(self.as_raw().as_bytes()) + } } diff --git a/eth2/utils/bls/src/aggregate_signature.rs b/eth2/utils/bls/src/aggregate_signature.rs index cf7ce78c26..f434feb0d7 100644 --- a/eth2/utils/bls/src/aggregate_signature.rs +++ b/eth2/utils/bls/src/aggregate_signature.rs @@ -129,6 +129,12 @@ impl AggregateSignature { is_empty: true, } } + + /// Return a hex string representation of the bytes of this signature. + #[cfg(test)] + pub fn as_hex_string(&self) -> String { + hex_encode(self.as_bytes()) + } } impl_ssz!(