Skip to content

Commit 68436e8

Browse files
committed
feat(dmq): add support for separate operational certificate and cold verification key in message
1 parent fc6cd06 commit 68436e8

File tree

2 files changed

+48
-31
lines changed

2 files changed

+48
-31
lines changed

internal/mithril-dmq/src/consumer/client/pallas.rs

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ use tokio::sync::{Mutex, MutexGuard};
77

88
use mithril_common::{
99
CardanoNetwork, StdResult,
10-
crypto_helper::{OpCert, TryFromBytes},
10+
crypto_helper::{
11+
OpCert, OpCertWithoutColdVerificationKey, TryFromBytes, ed25519::Ed25519VerificationKey,
12+
},
1113
entities::PartyId,
1214
logging::LoggerExtensions,
1315
};
@@ -113,8 +115,17 @@ impl<M: TryFromBytes + Debug> DmqConsumerClientPallas<M> {
113115
.0
114116
.into_iter()
115117
.map(|dmq_message| {
116-
let opcert = OpCert::try_from_bytes(&dmq_message.operational_certificate)
118+
let opcert_without_verification_key =
119+
OpCertWithoutColdVerificationKey::try_from_bytes(
120+
&dmq_message.operational_certificate,
121+
)
117122
.with_context(|| "Failed to parse operational certificate")?;
123+
let cold_verification_key =
124+
Ed25519VerificationKey::from_bytes(&dmq_message.cold_verification_key)
125+
.with_context(|| "Failed to parse cold verification key")?
126+
.into_inner();
127+
let opcert: OpCert =
128+
(opcert_without_verification_key, cold_verification_key).into();
118129
let party_id = opcert.compute_protocol_party_id()?;
119130
let payload = M::try_from_bytes(&dmq_message.msg_payload.msg_body)
120131
.with_context(|| "Failed to parse DMQ message body")?;
@@ -184,16 +195,17 @@ mod tests {
184195
},
185196
kes_signature: vec![0, 1, 2, 3],
186197
operational_certificate: vec![
187-
130, 132, 88, 32, 230, 80, 215, 83, 21, 9, 187, 108, 255, 215, 153, 140, 40,
188-
198, 142, 78, 200, 250, 98, 26, 9, 82, 32, 110, 161, 30, 176, 63, 205, 125,
189-
203, 41, 0, 0, 88, 64, 212, 171, 206, 39, 218, 5, 255, 3, 193, 52, 44, 198,
190-
171, 83, 19, 80, 114, 225, 186, 191, 156, 192, 84, 146, 245, 159, 31, 240, 9,
191-
247, 4, 87, 170, 168, 98, 199, 21, 139, 19, 190, 12, 251, 65, 215, 169, 26, 86,
192-
37, 137, 188, 17, 14, 178, 205, 175, 93, 39, 86, 4, 138, 187, 234, 95, 5, 88,
193-
32, 32, 253, 186, 201, 177, 11, 117, 135, 187, 167, 181, 188, 22, 59, 206, 105,
198+
132, 88, 32, 230, 80, 215, 83, 21, 9, 187, 108, 255, 215, 153, 140, 40, 198,
199+
142, 78, 200, 250, 98, 26, 9, 82, 32, 110, 161, 30, 176, 63, 205, 125, 203, 41,
200+
0, 0, 88, 64, 212, 171, 206, 39, 218, 5, 255, 3, 193, 52, 44, 198, 171, 83, 19,
201+
80, 114, 225, 186, 191, 156, 192, 84, 146, 245, 159, 31, 240, 9, 247, 4, 87,
202+
170, 168, 98, 199, 21, 139, 19, 190, 12, 251, 65, 215, 169, 26, 86, 37, 137,
203+
188, 17, 14, 178, 205, 175, 93, 39, 86, 4, 138, 187, 234, 95, 5,
204+
],
205+
cold_verification_key: vec![
206+
32, 253, 186, 201, 177, 11, 117, 135, 187, 167, 181, 188, 22, 59, 206, 105,
194207
231, 150, 215, 30, 78, 212, 76, 16, 252, 180, 72, 134, 137, 247, 161, 68,
195208
],
196-
cold_verification_key: vec![0, 1, 2, 3, 4, 5],
197209
},
198210
DmqMsg {
199211
msg_payload: DmqMsgPayload {
@@ -204,17 +216,17 @@ mod tests {
204216
},
205217
kes_signature: vec![1, 2, 3, 4],
206218
operational_certificate: vec![
207-
130, 132, 88, 32, 230, 80, 215, 83, 21, 9, 187, 108, 255, 215, 153, 140, 40,
208-
198, 142, 78, 200, 250, 98, 26, 9, 82, 32, 110, 161, 30, 176, 63, 205, 125,
209-
203, 41, 0, 0, 88, 64, 132, 4, 199, 39, 190, 173, 88, 102, 121, 117, 55, 62,
210-
39, 189, 113, 96, 175, 24, 171, 240, 74, 42, 139, 202, 128, 185, 44, 130, 209,
211-
77, 191, 122, 196, 224, 33, 158, 187, 156, 203, 190, 173, 150, 247, 87, 172,
212-
58, 153, 185, 157, 87, 128, 14, 187, 107, 187, 215, 105, 195, 107, 135, 172,
213-
43, 173, 9, 88, 32, 77, 75, 24, 6, 47, 133, 2, 89, 141, 224, 69, 202, 123, 105,
214-
240, 103, 245, 159, 147, 177, 110, 58, 248, 115, 58, 152, 138, 220, 35, 65,
215-
245, 200,
219+
132, 88, 32, 230, 80, 215, 83, 21, 9, 187, 108, 255, 215, 153, 140, 40, 198,
220+
142, 78, 200, 250, 98, 26, 9, 82, 32, 110, 161, 30, 176, 63, 205, 125, 203, 41,
221+
0, 0, 88, 64, 212, 171, 206, 39, 218, 5, 255, 3, 193, 52, 44, 198, 171, 83, 19,
222+
80, 114, 225, 186, 191, 156, 192, 84, 146, 245, 159, 31, 240, 9, 247, 4, 87,
223+
170, 168, 98, 199, 21, 139, 19, 190, 12, 251, 65, 215, 169, 26, 86, 37, 137,
224+
188, 17, 14, 178, 205, 175, 93, 39, 86, 4, 138, 187, 234, 95, 5,
225+
],
226+
cold_verification_key: vec![
227+
77, 75, 24, 6, 47, 133, 2, 89, 141, 224, 69, 202, 123, 105, 240, 103, 245, 159,
228+
147, 177, 110, 58, 248, 115, 58, 152, 138, 220, 35, 65, 245, 200,
216229
],
217-
cold_verification_key: vec![0, 1, 2, 3, 4, 5],
218230
},
219231
]
220232
}

internal/mithril-dmq/src/model/builder.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use pallas_network::miniprotocols::localmsgsubmission::{DmqMsg, DmqMsgPayload};
77
use mithril_cardano_node_chain::chain_observer::ChainObserver;
88
use mithril_common::{
99
StdResult,
10-
crypto_helper::{KesSigner, TryToBytes},
10+
crypto_helper::{KesSigner, SerDeShelleyFileFormat, TryToBytes},
1111
};
1212

1313
use crate::model::{DmqMessage, SystemUnixTimestampProvider, UnixTimestampProvider};
@@ -92,17 +92,16 @@ impl DmqMessageBuilder {
9292
.kes_signer
9393
.sign(&dmq_message_payload.bytes_to_sign()?, kes_period)
9494
.with_context(|| "Failed to KES sign message while building DMQ message")?;
95+
let operational_certificate_without_cold_verification_key =
96+
operational_certificate.get_opcert_without_cold_verification_key();
97+
let cold_verification_key = operational_certificate.get_cold_verification_key();
9598

9699
let dmq_message = DmqMsg {
97-
msg_payload: Self::enrich_msg_payload_with_id(DmqMsgPayload {
98-
msg_id: vec![],
99-
msg_body: message_bytes.to_vec(),
100-
kes_period: kes_period as u64,
101-
expires_at,
102-
}),
100+
msg_payload: dmq_message_payload,
103101
kes_signature: kes_signature.to_bytes_vec()?,
104-
operational_certificate: operational_certificate.to_bytes_vec()?, // TODO: remove the cold verification key in the op cert
105-
cold_verification_key: vec![], // TODO: fix
102+
operational_certificate: operational_certificate_without_cold_verification_key
103+
.to_cbor_bytes()?,
104+
cold_verification_key: cold_verification_key.to_bytes().to_vec(),
106105
};
107106

108107
Ok(dmq_message.into())
@@ -178,8 +177,14 @@ mod tests {
178177
DmqMsg {
179178
msg_payload: expected_msg_payload.clone(),
180179
kes_signature: kes_signature.to_bytes_vec().unwrap(),
181-
operational_certificate: operational_certificate.to_bytes_vec().unwrap(),
182-
cold_verification_key: vec![],
180+
operational_certificate: operational_certificate
181+
.get_opcert_without_cold_verification_key()
182+
.to_cbor_bytes()
183+
.unwrap(),
184+
cold_verification_key: operational_certificate
185+
.get_cold_verification_key()
186+
.to_bytes()
187+
.to_vec(),
183188
},
184189
dmq_message.clone().into()
185190
);

0 commit comments

Comments
 (0)