Skip to main content

commonware_consensus/aggregation/
scheme.rs

1//! Signing scheme implementations for `aggregation`.
2//!
3//! This module provides protocol-specific wrappers around the generic signing schemes
4//! in [`commonware_cryptography::certificate`]. Each wrapper binds the scheme's subject type to
5//! [`Item`], which represents the data being aggregated and signed.
6//!
7//! # Available Schemes
8//!
9//! - [`ed25519`]: Attributable signatures with individual verification. HSM-friendly,
10//!   no trusted setup required.
11//! - [`secp256r1`]: Attributable signatures with individual verification. HSM-friendly,
12//!   no trusted setup required.
13//! - [`bls12381_multisig`]: Attributable signatures with aggregated verification.
14//!   Compact certificates while preserving attribution.
15//! - [`bls12381_threshold`]: Non-attributable threshold signatures. Constant-size
16//!   certificates regardless of committee size.
17
18use super::types::Item;
19use commonware_cryptography::{certificate, Digest};
20
21/// Marker trait for signing schemes compatible with `aggregation`.
22///
23/// This trait binds a [`certificate::Scheme`] to the [`Item`] subject type used
24/// by the aggregation protocol. It is automatically implemented for any scheme
25/// whose subject type matches `&'a Item<D>`.
26pub trait Scheme<D: Digest>: for<'a> certificate::Scheme<Subject<'a, D> = &'a Item<D>> {}
27
28impl<D: Digest, S> Scheme<D> for S where S: for<'a> certificate::Scheme<Subject<'a, D> = &'a Item<D>>
29{}
30
31pub mod bls12381_multisig {
32    //! BLS12-381 multi-signature implementation of the
33    //! [`Scheme`](commonware_cryptography::certificate::Scheme) trait for `aggregation`.
34    //!
35    //! This scheme is attributable: certificates are compact while still preserving
36    //! per-validator attribution.
37
38    use crate::aggregation::types::{Item, Namespace};
39    use commonware_cryptography::impl_certificate_bls12381_multisig;
40
41    impl_certificate_bls12381_multisig!(&'a Item<D>, Namespace);
42}
43
44pub mod bls12381_threshold {
45    //! BLS12-381 threshold implementation of the [`Scheme`](commonware_cryptography::certificate::Scheme)
46    //! trait for `aggregation`.
47    //!
48    //! This scheme is non-attributable: partial signatures should not be exposed as
49    //! third-party evidence.
50
51    use crate::aggregation::types::{Item, Namespace};
52    use commonware_cryptography::impl_certificate_bls12381_threshold;
53
54    impl_certificate_bls12381_threshold!(&'a Item<D>, Namespace);
55}
56
57pub mod ed25519 {
58    //! Ed25519 implementation of the [`Scheme`](commonware_cryptography::certificate::Scheme) trait
59    //! for `aggregation`.
60    //!
61    //! This scheme is attributable: individual signatures can be safely exposed as
62    //! evidence of liveness or faults.
63
64    use crate::aggregation::types::{Item, Namespace};
65    use commonware_cryptography::impl_certificate_ed25519;
66
67    impl_certificate_ed25519!(&'a Item<D>, Namespace);
68}
69
70pub mod secp256r1 {
71    //! Secp256r1 implementation of the [`Scheme`](commonware_cryptography::certificate::Scheme) trait
72    //! for `aggregation`.
73    //!
74    //! This scheme is attributable: individual signatures can be safely exposed as
75    //! evidence of liveness or faults.
76
77    use crate::aggregation::types::{Item, Namespace};
78    use commonware_cryptography::impl_certificate_secp256r1;
79
80    impl_certificate_secp256r1!(&'a Item<D>, Namespace);
81}