mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-17 12:58:31 +00:00
Support multiple BLS implementations (#1335)
## Issue Addressed NA ## Proposed Changes - Refactor the `bls` crate to support multiple BLS "backends" (e.g., milagro, blst, etc). - Removes some duplicate, unused code in `common/rest_types/src/validator.rs`. - Removes the old "upgrade legacy keypairs" functionality (these were unencrypted keys that haven't been supported for a few testnets, no one should be using them anymore). ## Additional Info Most of the files changed are just inconsequential changes to function names. ## TODO - [x] Optimization levels - [x] Infinity point: https://github.com/supranational/blst/issues/11 - [x] Ensure milagro *and* blst are tested via CI - [x] What to do with unsafe code? - [x] Test infinity point in signature sets
This commit is contained in:
54
crypto/bls/src/generic_keypair.rs
Normal file
54
crypto/bls/src/generic_keypair.rs
Normal file
@@ -0,0 +1,54 @@
|
||||
use crate::{
|
||||
generic_public_key::{GenericPublicKey, TPublicKey},
|
||||
generic_secret_key::{GenericSecretKey, TSecretKey},
|
||||
generic_signature::TSignature,
|
||||
};
|
||||
use std::fmt;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
/// A simple wrapper around `PublicKey` and `GenericSecretKey`.
|
||||
#[derive(Clone)]
|
||||
pub struct GenericKeypair<Pub, Sec, Sig> {
|
||||
pub pk: GenericPublicKey<Pub>,
|
||||
pub sk: GenericSecretKey<Sig, Pub, Sec>,
|
||||
_phantom: PhantomData<Sig>,
|
||||
}
|
||||
|
||||
impl<Pub, Sec, Sig> GenericKeypair<Pub, Sec, Sig>
|
||||
where
|
||||
Pub: TPublicKey,
|
||||
Sec: TSecretKey<Sig, Pub>,
|
||||
Sig: TSignature<Pub>,
|
||||
{
|
||||
/// Instantiate `Self` from a public and secret key.
|
||||
///
|
||||
/// This function does not check to ensure that `pk` is derived from `sk`. It would be a logic
|
||||
/// error to supply such a `pk`.
|
||||
pub fn from_components(pk: GenericPublicKey<Pub>, sk: GenericSecretKey<Sig, Pub, Sec>) -> Self {
|
||||
Self {
|
||||
pk,
|
||||
sk,
|
||||
_phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
/// Instantiates `Self` from a randomly generated secret key.
|
||||
pub fn random() -> Self {
|
||||
let sk = GenericSecretKey::random();
|
||||
Self {
|
||||
pk: sk.public_key(),
|
||||
sk,
|
||||
_phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<Pub, Sec, Sig> fmt::Debug for GenericKeypair<Pub, Sec, Sig>
|
||||
where
|
||||
Pub: TPublicKey,
|
||||
{
|
||||
/// Defers to `self.pk` to avoid leaking the secret key.
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.pk.fmt(f)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user