Skip to content

Commit d7cda87

Browse files
committed
Update Certificate entity
* Add 'aggregate_verification_key' field to certificate * Add 'hash' computation in factory
1 parent 3e36b1e commit d7cda87

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
lines changed

mithril-common/src/entities.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use fixed::types::U8F24;
55
use serde::{Deserialize, Serialize};
6+
use std::collections::hash_map::DefaultHasher;
67
use std::hash::{Hash, Hasher};
78

89
pub type ImmutableFileNumber = u64;
@@ -103,9 +104,13 @@ pub struct Certificate {
103104
#[serde(rename = "completed_at")]
104105
pub completed_at: String,
105106

106-
/// The list of the participants (potential signers) with their stakes and verification keys
107-
#[serde(rename = "participants")]
108-
pub participants: Vec<SignerWithStake>,
107+
/// The list of the signers with their stakes and verification keys
108+
#[serde(rename = "signers")]
109+
pub signers: Vec<SignerWithStake>,
110+
111+
/// Aggregate verification key
112+
#[serde(rename = "aggregate_verification_key")]
113+
pub aggregate_verification_key: String,
109114

110115
/// STM multisignature created from a quorum of single signatures from the signers
111116
#[serde(rename = "multisignature")]
@@ -116,27 +121,32 @@ impl Certificate {
116121
/// Certificate factory
117122
#[allow(clippy::too_many_arguments)]
118123
pub fn new(
119-
hash: String,
120124
previous_hash: String,
121125
beacon: Beacon,
122126
protocol_parameters: ProtocolParameters,
123127
digest: String,
124128
started_at: String,
125129
completed_at: String,
126-
participants: Vec<SignerWithStake>,
130+
signers: Vec<SignerWithStake>,
131+
aggregate_verification_key: String,
127132
multisignature: String,
128133
) -> Certificate {
129-
Certificate {
130-
hash,
134+
let mut certificate = Certificate {
135+
hash: "".to_string(),
131136
previous_hash,
132137
beacon,
133138
protocol_parameters,
134139
digest,
135140
started_at,
136141
completed_at,
137-
participants,
142+
signers,
143+
aggregate_verification_key,
138144
multisignature,
139-
}
145+
};
146+
let mut hasher = DefaultHasher::new();
147+
certificate.hash(&mut hasher);
148+
certificate.hash = format!("{:x}", hasher.finish());
149+
certificate
140150
}
141151
}
142152

@@ -337,7 +347,6 @@ impl Stake {
337347
#[cfg(test)]
338348
mod tests {
339349
use super::*;
340-
use std::collections::hash_map::DefaultHasher;
341350

342351
#[test]
343352
fn test_protocol_parameters_partialeq() {

mithril-common/src/fake_data.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,17 @@ pub fn certificate(certificate_hash: String) -> entities::Certificate {
6868
let digest = format!("1{}", beacon.immutable_file_number).repeat(20);
6969
let started_at = "2006-01-02T15:04:05Z".to_string();
7070
let completed_at = "2006-01-02T15:04:05Z".to_string();
71-
let multisignature = format!("ABC{}", beacon.immutable_file_number).repeat(200);
71+
let aggregate_verification_key = format!("AVK{}", beacon.immutable_file_number).repeat(5);
72+
let multisignature = format!("MSIG{}", beacon.immutable_file_number).repeat(200);
7273
entities::Certificate::new(
73-
certificate_hash,
7474
previous_hash,
7575
beacon,
7676
protocol_parameters,
7777
digest,
7878
started_at,
7979
completed_at,
8080
signers,
81+
aggregate_verification_key,
8182
multisignature,
8283
)
8384
}

openapi.yaml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,8 @@ components:
353353
- digest
354354
- started_at
355355
- completed_at
356-
- participants
356+
- signers
357+
- aggregate_verification_key
357358
- multisignature
358359
properties:
359360
hash:
@@ -381,11 +382,15 @@ components:
381382
description: Date and time at which the certificate was completed (when the quorum of single signatures was reached so that a multisignature could be aggregated from them)
382383
type: string
383384
format: date-time
384-
participants:
385-
description: The list of the participants (potential signers) with their stakes and verification keys
385+
signers:
386+
description: The list of the signers with their stakes and verification keys
386387
type: array
387388
items:
388389
$ref: "#/components/schemas/SignerWithStake"
390+
aggregate_verification_key:
391+
description: Aggregate verification key used to verify the multisignature
392+
type: string
393+
format: bytes
389394
multisignature:
390395
description: STM multisignature created from a quorum of single signatures from the signers
391396
type: string

0 commit comments

Comments
 (0)