Add method to bls::PublicKey for short ID
This commit is contained in:
parent
b8ba0cd698
commit
87ffeaa833
@ -7,4 +7,5 @@ edition = "2018"
|
||||
[dependencies]
|
||||
bls-aggregates = { git = "https://github.com/sigp/signature-schemes" }
|
||||
hashing = { path = "../hashing" }
|
||||
hex = "0.3"
|
||||
ssz = { path = "../ssz" }
|
||||
|
@ -1,5 +1,6 @@
|
||||
use super::SecretKey;
|
||||
use bls_aggregates::PublicKey as RawPublicKey;
|
||||
use hex::encode as hex_encode;
|
||||
use ssz::{decode_ssz_list, ssz_encode, Decodable, DecodeError, Encodable, SszStream};
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
||||
@ -19,6 +20,15 @@ impl PublicKey {
|
||||
pub fn as_raw(&self) -> &RawPublicKey {
|
||||
&self.0
|
||||
}
|
||||
|
||||
/// Returns the last 6 bytes of the SSZ encoding of the public key, as a hex string.
|
||||
///
|
||||
/// Useful for providing a short identifier to the user.
|
||||
pub fn concatenated_hex_id(&self) -> String {
|
||||
let bytes = ssz_encode(self);
|
||||
let end_bytes = &bytes[bytes.len().saturating_sub(6)..bytes.len()];
|
||||
hex_encode(end_bytes)
|
||||
}
|
||||
}
|
||||
|
||||
impl Encodable for PublicKey {
|
||||
|
Loading…
Reference in New Issue
Block a user