diff --git a/rfcs/0001-messages.md b/rfcs/0001-messages.md index bdac4f8..a6dd776 100644 --- a/rfcs/0001-messages.md +++ b/rfcs/0001-messages.md @@ -136,18 +136,35 @@ FROST inherit types from `jubjub` such as `Scalar`, `ExtendedPoint`, `AffinePoin ## Validation -Validation is implemented to each new data type as needed. This will ensure the creation of valid messages before they are sent. For example, in the header sender and receiver can't be the same: +Validation is implemented to each new data type as needed. This will ensure the creation of valid messages before they are sent. We create a trait for this as follows: ```rust -impl Header { - pub fn validate(&self) { +pub trait Validate { + fn validate(&self) -> &Self; +} +``` + +And we implement where needed. For example, in the header sender and receiver can't be the same: + +```rust +impl Validate for Header { + fn validate(&self) -> &Self { if self.sender.0 == self.receiver.0 { panic!("sender and receiver are the same"); } + self } } ``` +Then to create a valid `Header` we call: + +```rust +let header = Validate::validate(&Header { + .. +}).clone(); +``` + ## Testing plan - Create a happy path unit test similar to https://github.com/ZcashFoundation/redjubjub/blob/frost-messages/tests/frost.rs#L7 and: