@@ -11,10 +11,10 @@ use key_registration::Cip36KeyRegistration;
1111use minicbor:: { Decode , Decoder } ;
1212use pallas:: ledger:: addresses:: ShelleyAddress ;
1313use registration_witness:: Cip36RegistrationWitness ;
14- use validation:: { validate_payment_address_network , validate_signature , validate_voting_keys } ;
14+ use validation:: { validate_cip36 , Cip36Validation } ;
1515use voting_pk:: VotingPubKey ;
1616
17- use crate :: { MetadatumLabel , MetadatumValue , MultiEraBlock , Network , TxnIndex } ;
17+ use crate :: { MetadatumLabel , MultiEraBlock , TxnIndex } ;
1818
1919/// CIP-36 Catalyst registration
2020#[ derive( Clone , Default , Debug ) ]
@@ -25,20 +25,9 @@ pub struct Cip36 {
2525 registration_witness : Cip36RegistrationWitness ,
2626 /// Is this a Catalyst strict registration?
2727 is_catalyst_strict : bool ,
28- }
29-
30- /// Validation value for CIP-36.
31- #[ allow( clippy:: struct_excessive_bools, clippy:: module_name_repetitions) ]
32- #[ derive( Clone , Default , Debug ) ]
33- pub ( crate ) struct Cip36Validation {
34- /// Is the signature valid? (signature in 61285)
35- pub is_valid_signature : bool ,
36- /// Is the payment address on the correct network?
37- pub is_valid_payment_address_network : bool ,
38- /// Is the voting keys valid?
39- pub is_valid_voting_keys : bool ,
40- /// Is the purpose valid? (Always 0 for Catalyst)
41- pub is_valid_purpose : bool ,
28+ /// CIP36 validation.
29+ #[ allow( dead_code) ]
30+ validation : Cip36Validation ,
4231}
4332
4433impl Cip36 {
@@ -97,24 +86,29 @@ impl Cip36 {
9786 } ,
9887 } ;
9988
89+ let mut validation_report = Vec :: new ( ) ;
90+ // If the code reach here, then the CIP36 decoding is successful.
91+ let validation = validate_cip36 (
92+ & key_registration,
93+ & registration_witness,
94+ is_catalyst_strict,
95+ network,
96+ k61284,
97+ & mut validation_report,
98+ ) ;
99+
100100 let cip36 = Self {
101101 key_registration,
102102 registration_witness,
103103 is_catalyst_strict,
104+ validation,
104105 } ;
105106
106- let mut validation_report = Vec :: new ( ) ;
107- // If the code reach here, then the CIP36 decoding is successful.
108- let validation = cip36. validate ( network, k61284, & mut validation_report) ;
109-
110- if validation. is_valid_signature
111- && validation. is_valid_payment_address_network
112- && validation. is_valid_voting_keys
113- && validation. is_valid_purpose
114- {
107+ if validation_report. is_empty ( ) {
115108 Ok ( cip36)
116109 } else {
117- bail ! ( "CIP-36 validation failed: {validation:?}, Reports: {validation_report:?}" )
110+ // If there are validation errors, the CIP36 is invalid
111+ bail ! ( "CIP-36 validation failed: {cip36:?}, Reports: {validation_report:?}" )
118112 }
119113 }
120114
@@ -179,36 +173,9 @@ impl Cip36 {
179173 self . is_catalyst_strict
180174 }
181175
182- /// Validation for CIP-36
183- /// The validation include the following:
184- /// * Signature validation of the registration witness 61285 against the stake public
185- /// key in key registration 61284.
186- /// * Payment address network validation against the network. The given network should
187- /// match the network tag within the payment address.
188- /// * Purpose validation, the purpose should be 0 for Catalyst (when
189- /// `is_strict_catalyst` is true).
190- /// * Voting keys validation, Catalyst supports only a single voting key per
191- /// registration when `is_strict_catalyst` is true.
192- ///
193- /// # Parameters
194- ///
195- /// * `network` - The blockchain network.
196- /// * `metadata` - The metadata value to be validated.
197- /// * `validation_report` - Validation report to store the validation result.
198- fn validate (
199- & self , network : Network , metadata : & MetadatumValue , validation_report : & mut Vec < String > ,
200- ) -> Cip36Validation {
201- let is_valid_signature = validate_signature ( self , metadata, validation_report) ;
202- let is_valid_payment_address_network =
203- validate_payment_address_network ( self , network, validation_report) . unwrap_or_default ( ) ;
204- let is_valid_voting_keys = validate_voting_keys ( self , validation_report) ;
205- let is_valid_purpose = validation:: validate_purpose ( self , validation_report) ;
206-
207- Cip36Validation {
208- is_valid_signature,
209- is_valid_payment_address_network,
210- is_valid_voting_keys,
211- is_valid_purpose,
212- }
176+ /// Get the CIP-36 validation.
177+ #[ must_use]
178+ pub fn validation ( & self ) -> & Cip36Validation {
179+ & self . validation
213180 }
214181}
0 commit comments