dkls23/setup/key_export/receiver.rs
1// Copyright (c) Silence Laboratories Pte. Ltd. All Rights Reserved.
2// This software is licensed under the Silence Laboratories License Agreement.
3
4use super::*;
5
6/// A message used for setting up key export receiving operations in a multi-party computation protocol.
7///
8/// This struct encapsulates all necessary information for receiving an exported key,
9/// including participant information, cryptographic keys, and protocol parameters.
10///
11/// # Type Parameters
12/// * `SK` - The type of signing key used for message signatures
13/// * `VK` - The type of verifying key used to verify message signatures
14/// * `MS` - The type of message signature
15pub struct KeyExportReceiver<
16 SK = NoSigningKey,
17 VK = NoVerifyingKey,
18 MS = NoSignature,
19> {
20 /// ID of the current party
21 party_id: usize,
22 /// Signing key for the current party
23 sk: SK,
24 /// Verifying keys for all participants
25 vk: Vec<VK>,
26 /// Instance identifier for the protocol
27 inst: InstanceId,
28 /// Time-to-live duration for messages
29 ttl: Duration,
30 /// Reference to the keyshare to be received
31 share: Arc<Keyshare>,
32 /// Private key used for decryption
33 enc_key: ReusableSecret,
34 /// Phantom data to hold the message signature type
35 marker: PhantomData<MS>,
36}
37
38impl<SK, VK, MS> KeyExportReceiver<SK, VK, MS> {
39 /// Creates a new setup message for key export receiving operations.
40 ///
41 /// # Arguments
42 /// * `inst` - Instance identifier for the protocol
43 /// * `sk` - Signing key for the current party
44 /// * `party_id` - ID of the current party
45 /// * `vk` - Vector of verifying keys for all participants
46 /// * `share` - Reference to the keyshare to be received
47 /// * `enc_key` - Private key used for decryption
48 ///
49 /// # Returns
50 /// A new `KeyExportReceiver` instance with default TTL
51 pub fn new(
52 inst: InstanceId,
53 sk: SK,
54 party_id: usize,
55 vk: Vec<VK>,
56 share: Arc<Keyshare>,
57 enc_key: ReusableSecret,
58 ) -> Self {
59 Self {
60 party_id,
61 sk,
62 vk,
63 inst,
64 ttl: Duration::from_secs(DEFAULT_TTL),
65 marker: PhantomData,
66 share,
67 enc_key,
68 }
69 }
70
71 /// Sets a custom time-to-live duration for messages.
72 ///
73 /// # Arguments
74 /// * `ttl` - The new time-to-live duration
75 ///
76 /// # Returns
77 /// The modified `KeyExportReceiver` instance
78 pub fn with_ttl(mut self, ttl: Duration) -> Self {
79 self.ttl = ttl;
80 self
81 }
82}
83
84impl<SK, VK, MS> ProtocolParticipant for KeyExportReceiver<SK, VK, MS>
85where
86 SK: Signer<MS>,
87 MS: SignatureEncoding,
88 VK: AsRef<[u8]> + Verifier<MS>,
89{
90 type MessageSignature = MS;
91 type MessageSigner = SK;
92 type MessageVerifier = VK;
93
94 /// Returns the total number of participants in the protocol.
95 fn total_participants(&self) -> usize {
96 self.vk.len()
97 }
98
99 /// Returns the index of the current participant.
100 fn participant_index(&self) -> usize {
101 self.party_id
102 }
103
104 /// Returns the instance identifier for the protocol.
105 fn instance_id(&self) -> &InstanceId {
106 &self.inst
107 }
108
109 /// Returns the time-to-live duration for messages.
110 fn message_ttl(&self) -> Duration {
111 self.ttl
112 }
113
114 /// Returns the verifying key for a specific participant.
115 ///
116 /// # Arguments
117 /// * `index` - The index of the participant
118 ///
119 /// # Returns
120 /// A reference to the verifying key
121 fn verifier(&self, index: usize) -> &Self::MessageVerifier {
122 &self.vk[index]
123 }
124
125 /// Returns the signing key for the current participant.
126 fn signer(&self) -> &Self::MessageSigner {
127 &self.sk
128 }
129}
130
131impl<SK, VK, MS> setup::KeyExportReceiverSetupMessage<ReusableSecret>
132 for KeyExportReceiver<SK, VK, MS>
133where
134 SK: Signer<MS>,
135 MS: SignatureEncoding,
136 VK: AsRef<[u8]> + Verifier<MS>,
137{
138 /// Returns a reference to the keyshare to be received.
139 fn keyshare(&self) -> &Keyshare {
140 &self.share
141 }
142
143 /// Returns the private key used for decryption.
144 fn receiver_private_key(&self) -> &ReusableSecret {
145 &self.enc_key
146 }
147}