b73c497be2
## 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
55 lines
1.5 KiB
Rust
55 lines
1.5 KiB
Rust
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)
|
|
}
|
|
}
|