Skip to content

Commit 90acdf7

Browse files
feat(frost-core): add (de)serialization for VerifiableSecretSharingSharingSharingCommitment
1 parent fc87f59 commit 90acdf7

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

frost-core/src/keys.rs

+23
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,11 @@ where
327327
.collect::<Result<_, Error<C>>>()
328328
}
329329

330+
/// Serialize to bytes
331+
pub fn serialize_whole(&self) -> Result<Vec<u8>, Error<C>> {
332+
self.serialize().map(|v| v.concat())
333+
}
334+
330335
/// Returns VerifiableSecretSharingCommitment from an iterator of serialized
331336
/// CoefficientCommitments (e.g. a [`Vec<Vec<u8>>`]).
332337
pub fn deserialize<I, V>(serialized_coefficient_commitments: I) -> Result<Self, Error<C>>
@@ -342,6 +347,24 @@ where
342347
Ok(Self::new(coefficient_commitments))
343348
}
344349

350+
/// Deserialize from bytes
351+
pub fn deserialize_whole(bytes: &[u8]) -> Result<Self, Error<C>> {
352+
// Get size from the size of the generator
353+
let generator = <C::Group>::generator();
354+
let len = <C::Group>::serialize(&generator)
355+
.expect("serializing the generator always works")
356+
.as_ref()
357+
.len();
358+
359+
let serialized_coefficient_commitments = bytes.chunks_exact(len);
360+
361+
if !serialized_coefficient_commitments.remainder().is_empty() {
362+
return Err(Error::InvalidCoefficient);
363+
}
364+
365+
Self::deserialize(serialized_coefficient_commitments)
366+
}
367+
345368
/// Get the VerifyingKey matching this commitment vector (which is the first
346369
/// element in the vector), or an error if the vector is empty.
347370
pub(crate) fn verifying_key(&self) -> Result<VerifyingKey<C>, Error<C>> {

0 commit comments

Comments
 (0)