mithril_stm/aggregate_signature/
aggregate_key.rs1use blake2::digest::{Digest, FixedOutput};
2use serde::{Deserialize, Serialize};
3
4use crate::merkle_tree::{BatchPath, MerkleTreeCommitmentBatchCompat};
5use crate::{ClosedKeyReg, Stake};
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
10#[serde(bound(
11 serialize = "BatchPath<D>: Serialize",
12 deserialize = "BatchPath<D>: Deserialize<'de>"
13))]
14pub struct StmAggrVerificationKey<D: Clone + Digest + FixedOutput> {
15 mt_commitment: MerkleTreeCommitmentBatchCompat<D>,
16 total_stake: Stake,
17}
18
19impl<D: Digest + Clone + FixedOutput> StmAggrVerificationKey<D> {
20 pub fn get_mt_commitment(&self) -> MerkleTreeCommitmentBatchCompat<D> {
21 self.mt_commitment.clone()
22 }
23
24 pub fn get_total_stake(&self) -> Stake {
25 self.total_stake
26 }
27}
28
29impl<D: Digest + Clone + FixedOutput> PartialEq for StmAggrVerificationKey<D> {
30 fn eq(&self, other: &Self) -> bool {
31 self.mt_commitment == other.mt_commitment && self.total_stake == other.total_stake
32 }
33}
34
35impl<D: Digest + Clone + FixedOutput> Eq for StmAggrVerificationKey<D> {}
36
37impl<D: Clone + Digest + FixedOutput> From<&ClosedKeyReg<D>> for StmAggrVerificationKey<D> {
38 fn from(reg: &ClosedKeyReg<D>) -> Self {
39 Self {
40 mt_commitment: reg.merkle_tree.to_commitment_batch_compat(),
41 total_stake: reg.total_stake,
42 }
43 }
44}