mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-14 10:22:38 +00:00
Update to signature-scheme 0.5.2
This commit is contained in:
@@ -27,7 +27,12 @@ impl AggregateSignature {
|
||||
///
|
||||
/// Only returns `true` if the set of keys in the `AggregatePublicKey` match the set of keys
|
||||
/// that signed the `AggregateSignature`.
|
||||
pub fn verify(&self, msg: &[u8], domain: u64, aggregate_public_key: &AggregatePublicKey) -> bool {
|
||||
pub fn verify(
|
||||
&self,
|
||||
msg: &[u8],
|
||||
domain: u64,
|
||||
aggregate_public_key: &AggregatePublicKey,
|
||||
) -> bool {
|
||||
self.0.verify(msg, domain, aggregate_public_key)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ fn extend_if_needed(hash: &mut Vec<u8>) {
|
||||
/// For some signature and public key, ensure that the signature message was the public key and it
|
||||
/// was signed by the secret key that corresponds to that public key.
|
||||
|
||||
|
||||
pub fn create_proof_of_possession(keypair: &Keypair) -> Signature {
|
||||
Signature::new(&ssz_encode(&keypair.pk), 0, &keypair.sk)
|
||||
}
|
||||
|
||||
@@ -21,7 +21,11 @@ impl Signature {
|
||||
/// Instantiate a new Signature from a message and a SecretKey, where the message has already
|
||||
/// been hashed.
|
||||
pub fn new_hashed(x_real_hashed: &[u8], x_imaginary_hashed: &[u8], sk: &SecretKey) -> Self {
|
||||
Signature(RawSignature::new_hashed(x_real_hashed, x_imaginary_hashed, sk.as_raw()))
|
||||
Signature(RawSignature::new_hashed(
|
||||
x_real_hashed,
|
||||
x_imaginary_hashed,
|
||||
sk.as_raw(),
|
||||
))
|
||||
}
|
||||
|
||||
/// Verify the Signature against a PublicKey.
|
||||
@@ -30,8 +34,14 @@ impl Signature {
|
||||
}
|
||||
|
||||
/// Verify the Signature against a PublicKey, where the message has already been hashed.
|
||||
pub fn verify_hashed(&self, x_real_hashed: &[u8], x_imaginary_hashed: &[u8], pk: &PublicKey) -> bool {
|
||||
self.0.verify_hashed(x_real_hashed, x_imaginary_hashed, pk.as_raw())
|
||||
pub fn verify_hashed(
|
||||
&self,
|
||||
x_real_hashed: &[u8],
|
||||
x_imaginary_hashed: &[u8],
|
||||
pk: &PublicKey,
|
||||
) -> bool {
|
||||
self.0
|
||||
.verify_hashed(x_real_hashed, x_imaginary_hashed, pk.as_raw())
|
||||
}
|
||||
|
||||
/// Returns the underlying signature.
|
||||
@@ -41,7 +51,9 @@ impl Signature {
|
||||
|
||||
/// Returns a new empty signature.
|
||||
pub fn empty_signature() -> Self {
|
||||
let empty: Vec<u8> = vec![0; 96];
|
||||
let mut empty: Vec<u8> = vec![0; 96];
|
||||
// TODO: Modify the way flags are used (b_flag should not be used for empty_signature in the future)
|
||||
empty[0] += u8::pow(2, 6);
|
||||
Signature(RawSignature::from_bytes(&empty).unwrap())
|
||||
}
|
||||
}
|
||||
@@ -99,9 +111,13 @@ mod tests {
|
||||
|
||||
let sig_as_bytes: Vec<u8> = sig.as_raw().as_bytes();
|
||||
|
||||
assert_eq!(sig_as_bytes.len(), 97);
|
||||
for one_byte in sig_as_bytes.iter() {
|
||||
assert_eq!(*one_byte, 0);
|
||||
assert_eq!(sig_as_bytes.len(), 96);
|
||||
for (i, one_byte) in sig_as_bytes.iter().enumerate() {
|
||||
if i == 0 {
|
||||
assert_eq!(*one_byte, u8::pow(2, 6));
|
||||
} else {
|
||||
assert_eq!(*one_byte, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user