pub trait BatchVerifier: PublicKey {
// Required method
fn verify_batch<'a, R, T, F>(
rng: &mut R,
items: &'a [T],
project: F,
strategy: &impl Strategy,
) -> bool
where R: CryptoRng,
T: Sync,
F: Fn(usize, &'a T) -> BatchEntry<'a, Self> + Sync;
}Required Methods§
Sourcefn verify_batch<'a, R, T, F>(
rng: &mut R,
items: &'a [T],
project: F,
strategy: &impl Strategy,
) -> bool
fn verify_batch<'a, R, T, F>( rng: &mut R, items: &'a [T], project: F, strategy: &impl Strategy, ) -> bool
Verify all signatures projected from a slice of items.
The projection receives each item’s original slice index. It must return the same entry for a given index and item.
Messages should not be hashed before calling this function. Any hashing required by the signature scheme is performed internally.
Each namespace must match the one used during signing exactly. Use distinct namespaces for distinct signing contexts to prevent replay attacks. For example, a signature on a message in the network layer must not authorize spending funds in the execution layer.
Returns false if the slice is empty or any signature is invalid.
§Examples
use commonware_cryptography::{
BatchEntry, BatchVerifier, Signer,
ed25519::{PrivateKey, PublicKey},
};
use commonware_math::algebra::Random;
use commonware_parallel::Sequential;
use commonware_utils::test_rng;
let key = PrivateKey::random(test_rng());
let public_key = key.public_key();
let namespace = b"example";
let records = [(b"message".as_slice(), key.sign(namespace, b"message"))];
assert!(PublicKey::verify_batch(
&mut test_rng(),
&records,
|_, (message, signature)| BatchEntry {
namespace,
message,
public_key: &public_key,
signature,
},
&Sequential,
));§Why Randomness?
When performing batch verification, it is often important to add some randomness
to prevent an attacker from constructing a malicious batch of signatures that pass
batch verification but are invalid individually. Abstractly, think of this as
there existing two valid signatures (c_1 and c_2) and an attacker proposing
(c_1 + d and c_2 - d).
You can read more about this here.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".