Skip to content

Commit f2611bb

Browse files
committed
Include signed message when computing Single signatures
1 parent d6991b1 commit f2611bb

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

mithril-common/src/entities/single_signatures.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub struct SingleSignatures {
3030
}
3131

3232
impl SingleSignatures {
33-
/// SingleSignature factory
33+
/// `SingleSignatures` factory
3434
pub fn new(
3535
party_id: PartyId,
3636
signature: ProtocolSingleSignature,
@@ -44,6 +44,21 @@ impl SingleSignatures {
4444
}
4545
}
4646

47+
/// `SingleSignatures` factory including the signed message
48+
pub fn new_with_signed_message(
49+
party_id: PartyId,
50+
signature: ProtocolSingleSignature,
51+
won_indexes: Vec<LotteryIndex>,
52+
signed_message: String,
53+
) -> SingleSignatures {
54+
SingleSignatures {
55+
party_id,
56+
signature,
57+
won_indexes,
58+
signed_message: Some(signed_message),
59+
}
60+
}
61+
4762
/// Convert this [SingleSignatures] to its corresponding [MithrilStm Signature][StmSig].
4863
pub fn to_protocol_signature(&self) -> StmSig {
4964
self.signature.clone().into()

mithril-common/src/protocol/single_signer.rs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@ impl SingleSigner {
2323
///
2424
/// If no lottery are won None will be returned.
2525
pub fn sign(&self, message: &ProtocolMessage) -> StdResult<Option<SingleSignatures>> {
26-
match self.protocol_signer.sign(message.compute_hash().as_bytes()) {
26+
let signed_message = message.compute_hash();
27+
match self.protocol_signer.sign(signed_message.as_bytes()) {
2728
Some(signature) => {
2829
let won_indexes = signature.indexes.clone();
2930

30-
Ok(Some(SingleSignatures::new(
31+
Ok(Some(SingleSignatures::new_with_signed_message(
3132
self.party_id.to_owned(),
3233
signature.into(),
3334
won_indexes,
35+
signed_message,
3436
)))
3537
}
3638
None => Ok(None),
@@ -72,4 +74,32 @@ mod test {
7274

7375
assert!(signature.is_some());
7476
}
77+
78+
#[test]
79+
fn embed_signed_message_in_issued_signature() {
80+
let fixture = MithrilFixtureBuilder::default().with_signers(3).build();
81+
let signers = fixture.signers_fixture();
82+
let signer = signers.first().unwrap();
83+
84+
let (single_signer, _) = SignerBuilder::new(
85+
&fixture.signers_with_stake(),
86+
&fixture.protocol_parameters(),
87+
)
88+
.unwrap()
89+
.build_test_single_signer(
90+
signer.signer_with_stake.clone(),
91+
signer.kes_secret_key_path(),
92+
)
93+
.unwrap();
94+
95+
let message = ProtocolMessage::default();
96+
let signature = single_signer
97+
.sign(&message)
98+
.expect("Single signer should be able to issue single signature");
99+
100+
assert_eq!(
101+
Some(message.compute_hash()),
102+
signature.and_then(|s| s.signed_message)
103+
);
104+
}
75105
}

0 commit comments

Comments
 (0)