diff --git a/anchor/common/ssv_types/src/message.rs b/anchor/common/ssv_types/src/message.rs index 4297b7cc9..b6f72ea8e 100644 --- a/anchor/common/ssv_types/src/message.rs +++ b/anchor/common/ssv_types/src/message.rs @@ -211,18 +211,26 @@ impl SSVMessage { msg_type: MsgType, msg_id: MessageId, data: Vec, + ) -> Result { + let ssv_message = Self::from_parts(msg_type, msg_id, data)?; + ssv_message.validate()?; + Ok(ssv_message) + } + + /// Bounds-checked construction without semantic validation; see [`Self::validate`]. + pub fn from_parts( + msg_type: MsgType, + msg_id: MessageId, + data: Vec, ) -> Result { let data = try_to_variable_list::(data, |provided, max| { SSVMessageError::SSVDataTooBig { provided, max } })?; - - let ssv_message = SSVMessage { + Ok(SSVMessage { msg_type, msg_id, data, - }; - ssv_message.validate()?; - Ok(ssv_message) + }) } /// Validate the SSV Message @@ -473,6 +481,19 @@ impl SignedSSVMessage { operator_ids: Vec, ssv_message: SSVMessage, full_data: Vec, + ) -> Result { + let signed_ssv_message = + Self::from_parts(signatures, operator_ids, ssv_message, full_data)?; + signed_ssv_message.validate()?; + Ok(signed_ssv_message) + } + + /// Bounds-checked construction without semantic validation; see [`Self::validate`]. + pub fn from_parts( + signatures: Vec<[u8; RSA_SIGNATURE_SIZE]>, + operator_ids: Vec, + ssv_message: SSVMessage, + full_data: Vec, ) -> Result { // Convert Vec<[u8; 256]> to VariableList, U13> // First convert each [u8; 256] to VariableList @@ -498,7 +519,7 @@ impl SignedSSVMessage { |provided, max| SignedSSVMessageError::TooManySignatures { provided, max }, )?; - let signed_ssv_message = SignedSSVMessage { + Ok(SignedSSVMessage { signatures, operator_ids: try_to_variable_list::( operator_ids, @@ -509,11 +530,7 @@ impl SignedSSVMessage { full_data, |provided, max| SignedSSVMessageError::FullDataTooLong { provided, max }, )?, - }; - - signed_ssv_message.validate()?; - - Ok(signed_ssv_message) + }) } /// Returns a reference to the signatures.