Skip to content

Commit 46732dc

Browse files
committed
Move CertificateMetadataMessage & SignerMessage to message_parts
1 parent 5661561 commit 46732dc

File tree

11 files changed

+83
-92
lines changed

11 files changed

+83
-92
lines changed

mithril-aggregator/src/message_adapters/to_certificate_message.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use mithril_common::entities::{Certificate, CertificateSignature};
22
use mithril_common::messages::{
3-
CertificateMessage, CertificateMetadataMessage, SignerWithStakeMessagePart, ToMessageAdapter,
3+
CertificateMessage, CertificateMetadataMessagePart, SignerWithStakeMessagePart,
4+
ToMessageAdapter,
45
};
56

67
/// Adapter to convert [Certificate] to [CertificateMessage] instances
@@ -9,7 +10,7 @@ pub struct ToCertificateMessageAdapter;
910
impl ToMessageAdapter<Certificate, CertificateMessage> for ToCertificateMessageAdapter {
1011
/// Method to trigger the conversion
1112
fn adapt(certificate: Certificate) -> CertificateMessage {
12-
let metadata = CertificateMetadataMessage {
13+
let metadata = CertificateMetadataMessagePart {
1314
protocol_version: certificate.metadata.protocol_version,
1415
protocol_parameters: certificate.metadata.protocol_parameters,
1516
initiated_at: certificate.metadata.initiated_at,

mithril-aggregator/src/message_adapters/to_certificate_pending_message.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use mithril_common::{
22
entities::{CertificatePending, Signer},
3-
messages::{CertificatePendingMessage, SignerMessage, ToMessageAdapter},
3+
messages::{CertificatePendingMessage, SignerMessagePart, ToMessageAdapter},
44
};
55

66
/// Adapter to turn [CertificatePending] instances into [CertificatePendingMessage].
@@ -23,10 +23,10 @@ impl ToMessageAdapter<CertificatePending, CertificatePendingMessage>
2323
}
2424

2525
impl ToCertificatePendingMessageAdapter {
26-
fn adapt_signers(signers: Vec<Signer>) -> Vec<SignerMessage> {
26+
fn adapt_signers(signers: Vec<Signer>) -> Vec<SignerMessagePart> {
2727
signers
2828
.into_iter()
29-
.map(|signer| SignerMessage {
29+
.map(|signer| SignerMessagePart {
3030
party_id: signer.party_id,
3131
verification_key: signer.verification_key.try_into().unwrap(),
3232
verification_key_signature: signer

mithril-client/src/aggregator_client/certificate_client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl CertificateRetriever for CertificateClient {
6767
#[cfg(test)]
6868
mod tests {
6969
use mithril_common::entities::CertificateSignature;
70-
use mithril_common::messages::{CertificateMetadataMessage, SignerWithStakeMessagePart};
70+
use mithril_common::messages::{CertificateMetadataMessagePart, SignerWithStakeMessagePart};
7171
use mithril_common::test_utils::fake_data;
7272

7373
use crate::aggregator_client::MockAggregatorHTTPClient;
@@ -97,7 +97,7 @@ mod tests {
9797
hash: certificate_hash.clone(),
9898
previous_hash: previous_hash.clone(),
9999
beacon: certificate.beacon.clone(),
100-
metadata: CertificateMetadataMessage {
100+
metadata: CertificateMetadataMessagePart {
101101
protocol_version: certificate.metadata.protocol_version.clone(),
102102
protocol_parameters: certificate.metadata.protocol_parameters.clone(),
103103
initiated_at: certificate.metadata.initiated_at,

mithril-common/src/messages/certificate.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
use crate::{
2-
entities::{Beacon, ProtocolMessage, ProtocolMessagePartKey},
3-
messages::certificate_metadata::CertificateMetadataMessage,
4-
};
1+
use serde::{Deserialize, Serialize};
52

3+
use crate::entities::{Beacon, ProtocolMessage, ProtocolMessagePartKey};
4+
use crate::messages::CertificateMetadataMessagePart;
65
use crate::test_utils::fake_keys;
7-
use serde::{Deserialize, Serialize};
86

97
/// Message structure of a certificate
108
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
@@ -26,7 +24,7 @@ pub struct CertificateMessage {
2624

2725
/// Certificate metadata
2826
/// aka METADATA(p,n)
29-
pub metadata: CertificateMetadataMessage,
27+
pub metadata: CertificateMetadataMessagePart,
3028

3129
/// Structured message that is used to created the signed message
3230
/// aka MSG(p,n) U AVK(n-1)
@@ -66,7 +64,7 @@ impl CertificateMessage {
6664
hash: "hash".to_string(),
6765
previous_hash: "previous_hash".to_string(),
6866
beacon: Beacon::new("testnet".to_string(), 10, 100),
69-
metadata: CertificateMetadataMessage::dummy(),
67+
metadata: CertificateMetadataMessagePart::dummy(),
7068
protocol_message: protocol_message.clone(),
7169
signed_message: "signed_message".to_string(),
7270
aggregate_verification_key: "aggregate_verification_key".to_string(),
@@ -96,7 +94,7 @@ mod tests {
9694
hash: "hash".to_string(),
9795
previous_hash: "previous_hash".to_string(),
9896
beacon: Beacon::new("testnet".to_string(), 10, 100),
99-
metadata: CertificateMetadataMessage {
97+
metadata: CertificateMetadataMessagePart {
10098
protocol_version: "0.1.0".to_string(),
10199
protocol_parameters: ProtocolParameters::new(1000, 100, 0.123),
102100
initiated_at: DateTime::parse_from_rfc3339("2024-02-12T13:11:47Z")

mithril-common/src/messages/certificate_pending.rs

Lines changed: 8 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
use serde::{Deserialize, Serialize};
22

3-
use crate::{
4-
crypto_helper::KESPeriod,
5-
entities::{
6-
Beacon, HexEncodedOpCert, HexEncodedVerificationKey, HexEncodedVerificationKeySignature,
7-
PartyId, ProtocolParameters, SignedEntityType,
8-
},
9-
test_utils::fake_keys,
10-
};
3+
use crate::entities::{Beacon, ProtocolParameters, SignedEntityType};
4+
use crate::messages::SignerMessagePart;
115

126
/// Structure to transport [crate::entities::CertificatePending] data.
137
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
@@ -28,10 +22,10 @@ pub struct CertificatePendingMessage {
2822
pub next_protocol_parameters: ProtocolParameters,
2923

3024
/// Current Signers
31-
pub signers: Vec<SignerMessage>,
25+
pub signers: Vec<SignerMessagePart>,
3226

3327
/// Signers that will be able to sign on the next epoch
34-
pub next_signers: Vec<SignerMessage>,
28+
pub next_signers: Vec<SignerMessagePart>,
3529
}
3630

3731
impl CertificatePendingMessage {
@@ -50,55 +44,8 @@ impl CertificatePendingMessage {
5044
m: 1000,
5145
phi_f: 0.65,
5246
},
53-
signers: [SignerMessage::dummy()].to_vec(),
54-
next_signers: [SignerMessage::dummy()].to_vec(),
55-
}
56-
}
57-
}
58-
59-
// todo: move to message_parts
60-
/// Signer Message
61-
#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
62-
pub struct SignerMessage {
63-
/// The unique identifier of the signer
64-
// TODO: Should be removed once the signer certification is fully deployed
65-
pub party_id: PartyId,
66-
67-
/// The public key used to authenticate signer signature
68-
pub verification_key: HexEncodedVerificationKey,
69-
70-
/// The encoded signer 'Mithril verification key' signature (signed by the
71-
/// Cardano node KES secret key).
72-
// TODO: Option should be removed once the signer certification is fully
73-
// deployed.
74-
#[serde(skip_serializing_if = "Option::is_none")]
75-
pub verification_key_signature: Option<HexEncodedVerificationKeySignature>,
76-
77-
/// The encoded operational certificate of stake pool operator attached to
78-
/// the signer node.
79-
// TODO: Option should be removed once the signer certification is fully
80-
// deployed.
81-
#[serde(skip_serializing_if = "Option::is_none")]
82-
pub operational_certificate: Option<HexEncodedOpCert>,
83-
84-
/// The KES period used to compute the verification key signature
85-
// TODO: This KES period should not be used as is and should probably be
86-
// within an allowed range of KES periods for the epoch.
87-
#[serde(skip_serializing_if = "Option::is_none")]
88-
pub kes_period: Option<KESPeriod>,
89-
}
90-
91-
impl SignerMessage {
92-
/// Return a dummy test entity (test-only).
93-
pub fn dummy() -> Self {
94-
Self {
95-
party_id: "pool1m8crhnqj5k2kyszf5j2scshupystyxc887zdfrpzh6ty6eun4fx".to_string(),
96-
verification_key: fake_keys::signer_verification_key()[0].to_string(),
97-
verification_key_signature: Some(
98-
fake_keys::signer_verification_key_signature()[0].to_string(),
99-
),
100-
operational_certificate: Some(fake_keys::operational_certificate()[0].to_string()),
101-
kes_period: Some(6),
47+
signers: [SignerMessagePart::dummy()].to_vec(),
48+
next_signers: [SignerMessagePart::dummy()].to_vec(),
10249
}
10350
}
10451
}
@@ -129,7 +76,7 @@ mod tests {
12976
phi_f: 0.65,
13077
},
13178
signers: vec![
132-
SignerMessage {
79+
SignerMessagePart {
13380
party_id: "123".to_string(),
13481
verification_key: "7b22766b223a5b3134332c3136312c3235352c34382c37382c35372c3230342c3232302c32352c3232312c3136342c3235322c3234382c31342c35362c3132362c3138362c3133352c3232382c3138382c3134352c3138312c35322c3230302c39372c39392c3231332c34362c302c3139392c3139332c38392c3138372c38382c32392c3133352c3137332c3234342c38362c33362c38332c35342c36372c3136342c362c3133372c39342c37322c362c3130352c3132382c3132382c39332c34382c3137362c31312c342c3234362c3133382c34382c3138302c3133332c39302c3134322c3139322c32342c3139332c3131312c3134322c33312c37362c3131312c3131302c3233342c3135332c39302c3230382c3139322c33312c3132342c39352c3130322c34392c3135382c39392c35322c3232302c3136352c39342c3235312c36382c36392c3132312c31362c3232342c3139345d2c22706f70223a5b3136382c35302c3233332c3139332c31352c3133362c36352c37322c3132332c3134382c3132392c3137362c33382c3139382c3230392c34372c32382c3230342c3137362c3134342c35372c3235312c34322c32382c36362c37362c38392c39372c3135382c36332c35342c3139382c3139342c3137362c3133352c3232312c31342c3138352c3139372c3232352c3230322c39382c3234332c37342c3233332c3232352c3134332c3135312c3134372c3137372c3137302c3131372c36362c3136352c36362c36322c33332c3231362c3233322c37352c36382c3131342c3139352c32322c3130302c36352c34342c3139382c342c3136362c3130322c3233332c3235332c3234302c35392c3137352c36302c3131372c3134322c3131342c3134302c3132322c31372c38372c3131302c3138372c312c31372c31302c3139352c3135342c31332c3234392c38362c35342c3232365d7d".to_string(),
13582
verification_key_signature: None,
@@ -138,7 +85,7 @@ mod tests {
13885
}
13986
],
14087
next_signers: vec![
141-
SignerMessage {
88+
SignerMessagePart {
14289
party_id: "123".to_string(),
14390
verification_key: "7b22766b223a5b3134332c3136312c3235352c34382c37382c35372c3230342c3232302c32352c3232312c3136342c3235322c3234382c31342c35362c3132362c3138362c3133352c3232382c3138382c3134352c3138312c35322c3230302c39372c39392c3231332c34362c302c3139392c3139332c38392c3138372c38382c32392c3133352c3137332c3234342c38362c33362c38332c35342c36372c3136342c362c3133372c39342c37322c362c3130352c3132382c3132382c39332c34382c3137362c31312c342c3234362c3133382c34382c3138302c3133332c39302c3134322c3139322c32342c3139332c3131312c3134322c33312c37362c3131312c3131302c3233342c3135332c39302c3230382c3139322c33312c3132342c39352c3130322c34392c3135382c39392c35322c3232302c3136352c39342c3235312c36382c36392c3132312c31362c3232342c3139345d2c22706f70223a5b3136382c35302c3233332c3139332c31352c3133362c36352c37322c3132332c3134382c3132392c3137362c33382c3139382c3230392c34372c32382c3230342c3137362c3134342c35372c3235312c34322c32382c36362c37362c38392c39372c3135382c36332c35342c3139382c3139342c3137362c3133352c3232312c31342c3138352c3139372c3232352c3230322c39382c3234332c37342c3233332c3232352c3134332c3135312c3134372c3137372c3137302c3131372c36362c3136352c36362c36322c33332c3231362c3233322c37352c36382c3131342c3139352c32322c3130302c36352c34342c3139382c342c3136362c3130322c3233332c3235332c3234302c35392c3137352c36302c3131372c3134322c3131342c3134302c3132322c31372c38372c3131302c3138372c312c31372c31302c3139352c3135342c31332c3234392c38362c35342c3232365d7d".to_string(),
14491
verification_key_signature: None,

mithril-common/src/messages/certificate_metadata.rs renamed to mithril-common/src/messages/message_parts/certificate_metadata.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ use serde::{Deserialize, Serialize};
88

99
use super::SignerWithStakeMessagePart;
1010

11-
// todo: move to message_parts
1211
/// CertificateMetadata represents the metadata associated to a Certificate
1312
#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
14-
pub struct CertificateMetadataMessage {
13+
pub struct CertificateMetadataMessagePart {
1514
/// Protocol Version (semver)
1615
/// Useful to achieve backward compatibility of the certificates (including of the multi signature)
1716
/// part of METADATA(p,n)
@@ -38,7 +37,7 @@ pub struct CertificateMetadataMessage {
3837
pub signers: Vec<SignerWithStakeMessagePart>,
3938
}
4039

41-
impl CertificateMetadataMessage {
40+
impl CertificateMetadataMessagePart {
4241
/// CertificateMetadata factory
4342
pub fn dummy() -> Self {
4443
let initiated_at = DateTime::parse_from_rfc3339("2024-02-12T13:11:47Z")
@@ -76,8 +75,8 @@ impl CertificateMetadataMessage {
7675
mod tests {
7776
use super::*;
7877

79-
fn golden_message() -> CertificateMetadataMessage {
80-
CertificateMetadataMessage {
78+
fn golden_message() -> CertificateMetadataMessagePart {
79+
CertificateMetadataMessagePart {
8180
protocol_version: "0.1.0".to_string(),
8281
protocol_parameters: ProtocolParameters::new(1000, 100, 0.123),
8382
initiated_at: DateTime::parse_from_rfc3339("2024-02-12T13:11:47Z")
@@ -132,7 +131,7 @@ mod tests {
132131
}
133132
]
134133
}"#;
135-
let message: CertificateMetadataMessage = serde_json::from_str(json).expect(
134+
let message: CertificateMetadataMessagePart = serde_json::from_str(json).expect(
136135
"This JSON is expected to be successfully parsed into a CertificateMetadataMessage instance.",
137136
);
138137

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
mod certificate_metadata;
12
mod signer;
23

3-
pub use signer::SignerWithStakeMessagePart;
4+
pub use certificate_metadata::CertificateMetadataMessagePart;
5+
pub use signer::{SignerMessagePart, SignerWithStakeMessagePart};

mithril-common/src/messages/message_parts/signer.rs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{
99
};
1010
use serde::{Deserialize, Serialize};
1111

12-
/// Signer Message
12+
/// Signer with Stake Message
1313
#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
1414
pub struct SignerWithStakeMessagePart {
1515
/// The unique identifier of the signer
@@ -107,3 +107,49 @@ impl From<SignerWithStake> for SignerWithStakeMessagePart {
107107
}
108108
}
109109
}
110+
111+
/// Signer Message
112+
#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
113+
pub struct SignerMessagePart {
114+
/// The unique identifier of the signer
115+
// TODO: Should be removed once the signer certification is fully deployed
116+
pub party_id: PartyId,
117+
118+
/// The public key used to authenticate signer signature
119+
pub verification_key: HexEncodedVerificationKey,
120+
121+
/// The encoded signer 'Mithril verification key' signature (signed by the
122+
/// Cardano node KES secret key).
123+
// TODO: Option should be removed once the signer certification is fully
124+
// deployed.
125+
#[serde(skip_serializing_if = "Option::is_none")]
126+
pub verification_key_signature: Option<HexEncodedVerificationKeySignature>,
127+
128+
/// The encoded operational certificate of stake pool operator attached to
129+
/// the signer node.
130+
// TODO: Option should be removed once the signer certification is fully
131+
// deployed.
132+
#[serde(skip_serializing_if = "Option::is_none")]
133+
pub operational_certificate: Option<HexEncodedOpCert>,
134+
135+
/// The KES period used to compute the verification key signature
136+
// TODO: This KES period should not be used as is and should probably be
137+
// within an allowed range of KES periods for the epoch.
138+
#[serde(skip_serializing_if = "Option::is_none")]
139+
pub kes_period: Option<KESPeriod>,
140+
}
141+
142+
impl SignerMessagePart {
143+
/// Return a dummy test entity (test-only).
144+
pub fn dummy() -> Self {
145+
Self {
146+
party_id: "pool1m8crhnqj5k2kyszf5j2scshupystyxc887zdfrpzh6ty6eun4fx".to_string(),
147+
verification_key: fake_keys::signer_verification_key()[0].to_string(),
148+
verification_key_signature: Some(
149+
fake_keys::signer_verification_key_signature()[0].to_string(),
150+
),
151+
operational_certificate: Some(fake_keys::operational_certificate()[0].to_string()),
152+
kes_period: Some(6),
153+
}
154+
}
155+
}

mithril-common/src/messages/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//! This module aims at providing shared structures for API communications.
33
mod certificate;
44
mod certificate_list;
5-
mod certificate_metadata;
65
mod certificate_pending;
76
mod epoch_settings;
87
mod interface;
@@ -18,8 +17,7 @@ pub use certificate::CertificateMessage;
1817
pub use certificate_list::{
1918
CertificateListItemMessage, CertificateListItemMessageMetadata, CertificateListMessage,
2019
};
21-
pub use certificate_metadata::CertificateMetadataMessage;
22-
pub use certificate_pending::{CertificatePendingMessage, SignerMessage};
20+
pub use certificate_pending::CertificatePendingMessage;
2321
pub use epoch_settings::EpochSettingsMessage;
2422
pub use interface::*;
2523
pub use message_parts::*;

mithril-common/src/test_utils/apispec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ mod tests {
195195

196196
use super::*;
197197
use crate::entities;
198-
use crate::messages::{CertificatePendingMessage, SignerMessage};
198+
use crate::messages::{CertificatePendingMessage, SignerMessagePart};
199199
use crate::test_utils::fake_data;
200200

201201
#[test]
@@ -217,7 +217,7 @@ mod tests {
217217
assert!(APISpec::from_file(&APISpec::get_defaut_spec_file())
218218
.method(Method::POST.as_str())
219219
.path("/register-signer")
220-
.validate_request(&SignerMessage::dummy())
220+
.validate_request(&SignerMessagePart::dummy())
221221
.unwrap()
222222
.validate_response(&Response::<Bytes>::new(Bytes::new()))
223223
.is_err());

0 commit comments

Comments
 (0)