mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-22 07:18:25 +00:00
Implement tree states & hierarchical state DB
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
use crate::{
|
||||
generic_aggregate_public_key::TAggregatePublicKey,
|
||||
generic_aggregate_signature::TAggregateSignature,
|
||||
generic_public_key::{GenericPublicKey, TPublicKey, PUBLIC_KEY_BYTES_LEN},
|
||||
generic_public_key::{
|
||||
GenericPublicKey, TPublicKey, PUBLIC_KEY_BYTES_LEN, PUBLIC_KEY_UNCOMPRESSED_BYTES_LEN,
|
||||
},
|
||||
generic_secret_key::TSecretKey,
|
||||
generic_signature::{TSignature, SIGNATURE_BYTES_LEN},
|
||||
Error, Hash256, ZeroizeHash, INFINITY_SIGNATURE,
|
||||
BlstError, Error, Hash256, ZeroizeHash, INFINITY_SIGNATURE,
|
||||
};
|
||||
pub use blst::min_pk as blst_core;
|
||||
use blst::{blst_scalar, BLST_ERROR};
|
||||
@@ -123,6 +125,10 @@ impl TPublicKey for blst_core::PublicKey {
|
||||
self.compress()
|
||||
}
|
||||
|
||||
fn serialize_uncompressed(&self) -> [u8; PUBLIC_KEY_UNCOMPRESSED_BYTES_LEN] {
|
||||
blst_core::PublicKey::serialize(self)
|
||||
}
|
||||
|
||||
fn deserialize(bytes: &[u8]) -> Result<Self, Error> {
|
||||
// key_validate accepts uncompressed bytes too so enforce byte length here.
|
||||
// It also does subgroup checks, noting infinity check is done in `generic_public_key.rs`.
|
||||
@@ -134,6 +140,19 @@ impl TPublicKey for blst_core::PublicKey {
|
||||
}
|
||||
Self::key_validate(bytes).map_err(Into::into)
|
||||
}
|
||||
|
||||
fn deserialize_uncompressed(bytes: &[u8]) -> Result<Self, Error> {
|
||||
if bytes.len() != PUBLIC_KEY_UNCOMPRESSED_BYTES_LEN {
|
||||
return Err(Error::InvalidByteLength {
|
||||
got: bytes.len(),
|
||||
expected: PUBLIC_KEY_UNCOMPRESSED_BYTES_LEN,
|
||||
});
|
||||
}
|
||||
// Ensure we use the `blst` function rather than the one from this trait.
|
||||
let result: Result<Self, BlstError> = Self::deserialize(bytes);
|
||||
let key = result?;
|
||||
Ok(key)
|
||||
}
|
||||
}
|
||||
|
||||
/// A wrapper that allows for `PartialEq` and `Clone` impls.
|
||||
|
||||
Reference in New Issue
Block a user