2019-06-03 03:26:22 +00:00
|
|
|
extern crate milagro_bls;
|
2019-02-14 01:09:18 +00:00
|
|
|
extern crate ssz;
|
|
|
|
|
2019-05-06 05:03:20 +00:00
|
|
|
#[macro_use]
|
|
|
|
mod macros;
|
2019-02-14 01:09:18 +00:00
|
|
|
mod keypair;
|
2019-08-06 03:49:11 +00:00
|
|
|
mod public_key_bytes;
|
2020-05-29 04:39:33 +00:00
|
|
|
mod secret_hash;
|
2019-02-14 01:09:18 +00:00
|
|
|
mod secret_key;
|
2019-08-06 03:49:11 +00:00
|
|
|
mod signature_bytes;
|
2019-08-29 01:34:25 +00:00
|
|
|
mod signature_set;
|
2019-03-21 23:08:40 +00:00
|
|
|
|
2019-05-14 12:09:57 +00:00
|
|
|
pub use crate::keypair::Keypair;
|
2019-08-06 03:49:11 +00:00
|
|
|
pub use crate::public_key_bytes::PublicKeyBytes;
|
2019-05-14 12:09:57 +00:00
|
|
|
pub use crate::secret_key::SecretKey;
|
2019-08-06 03:49:11 +00:00
|
|
|
pub use crate::signature_bytes::SignatureBytes;
|
2020-05-29 04:39:33 +00:00
|
|
|
pub use secret_hash::SecretHash;
|
2020-04-28 03:15:46 +00:00
|
|
|
pub use signature_set::{verify_signature_sets, SignatureSet};
|
2019-03-21 23:08:40 +00:00
|
|
|
|
2020-05-05 23:12:28 +00:00
|
|
|
#[cfg(feature = "arbitrary")]
|
|
|
|
pub use arbitrary;
|
|
|
|
|
2019-05-14 12:09:57 +00:00
|
|
|
#[cfg(feature = "fake_crypto")]
|
|
|
|
mod fake_aggregate_public_key;
|
2019-04-02 06:51:12 +00:00
|
|
|
#[cfg(feature = "fake_crypto")]
|
2019-03-21 23:08:40 +00:00
|
|
|
mod fake_aggregate_signature;
|
2019-04-02 06:51:12 +00:00
|
|
|
#[cfg(feature = "fake_crypto")]
|
2019-05-14 12:09:57 +00:00
|
|
|
mod fake_public_key;
|
|
|
|
#[cfg(feature = "fake_crypto")]
|
2019-03-21 23:08:40 +00:00
|
|
|
mod fake_signature;
|
2019-05-14 12:09:57 +00:00
|
|
|
|
|
|
|
#[cfg(not(feature = "fake_crypto"))]
|
|
|
|
mod aggregate_public_key;
|
|
|
|
#[cfg(not(feature = "fake_crypto"))]
|
|
|
|
mod aggregate_signature;
|
|
|
|
#[cfg(not(feature = "fake_crypto"))]
|
|
|
|
mod public_key;
|
|
|
|
#[cfg(not(feature = "fake_crypto"))]
|
|
|
|
mod signature;
|
|
|
|
|
2019-04-02 06:51:12 +00:00
|
|
|
#[cfg(feature = "fake_crypto")]
|
2019-05-14 12:09:57 +00:00
|
|
|
pub use fakes::*;
|
2019-04-02 06:51:12 +00:00
|
|
|
#[cfg(feature = "fake_crypto")]
|
2019-05-14 12:09:57 +00:00
|
|
|
mod fakes {
|
|
|
|
pub use crate::fake_aggregate_public_key::FakeAggregatePublicKey as AggregatePublicKey;
|
|
|
|
pub use crate::fake_aggregate_signature::FakeAggregateSignature as AggregateSignature;
|
|
|
|
pub use crate::fake_public_key::FakePublicKey as PublicKey;
|
|
|
|
pub use crate::fake_signature::FakeSignature as Signature;
|
|
|
|
}
|
2019-02-14 01:09:18 +00:00
|
|
|
|
2019-05-14 12:09:57 +00:00
|
|
|
#[cfg(not(feature = "fake_crypto"))]
|
|
|
|
pub use reals::*;
|
|
|
|
#[cfg(not(feature = "fake_crypto"))]
|
|
|
|
mod reals {
|
|
|
|
pub use crate::aggregate_public_key::AggregatePublicKey;
|
|
|
|
pub use crate::aggregate_signature::AggregateSignature;
|
|
|
|
pub use crate::public_key::PublicKey;
|
|
|
|
pub use crate::signature::Signature;
|
|
|
|
}
|
2019-02-14 01:09:18 +00:00
|
|
|
|
2019-02-18 01:06:47 +00:00
|
|
|
pub const BLS_AGG_SIG_BYTE_SIZE: usize = 96;
|
2019-03-25 07:02:37 +00:00
|
|
|
pub const BLS_SIG_BYTE_SIZE: usize = 96;
|
2020-04-28 08:27:33 +00:00
|
|
|
pub const BLS_SECRET_KEY_BYTE_SIZE: usize = 32;
|
2019-03-26 05:45:25 +00:00
|
|
|
pub const BLS_PUBLIC_KEY_BYTE_SIZE: usize = 48;
|
2019-02-14 01:09:18 +00:00
|
|
|
|
2019-08-08 01:39:47 +00:00
|
|
|
use eth2_hashing::hash;
|
2019-02-14 01:09:18 +00:00
|
|
|
use ssz::ssz_encode;
|
|
|
|
|
2019-03-07 05:15:38 +00:00
|
|
|
/// Returns the withdrawal credentials for a given public key.
|
|
|
|
pub fn get_withdrawal_credentials(pubkey: &PublicKey, prefix_byte: u8) -> Vec<u8> {
|
|
|
|
let hashed = hash(&ssz_encode(pubkey));
|
|
|
|
let mut prefixed = vec![prefix_byte];
|
|
|
|
prefixed.extend_from_slice(&hashed[1..]);
|
|
|
|
|
|
|
|
prefixed
|
|
|
|
}
|
|
|
|
|
2019-02-14 01:09:18 +00:00
|
|
|
pub fn bls_verify_aggregate(
|
|
|
|
pubkey: &AggregatePublicKey,
|
|
|
|
message: &[u8],
|
|
|
|
signature: &AggregateSignature,
|
|
|
|
) -> bool {
|
2020-02-10 23:19:36 +00:00
|
|
|
signature.verify(message, pubkey)
|
2019-02-14 01:09:18 +00:00
|
|
|
}
|