@@ -46,7 +46,7 @@ impl RegistrationChain {
4646 ///
4747 /// # Errors
4848 /// - Propagates any I/O or provider-level errors encountered while checking key
49- /// ownership (e.g., database lookup failures).
49+ /// ownership (e.g., database lookup failures).
5050 pub async fn new < State > (
5151 cip509 : & Cip509 ,
5252 state : & mut State ,
@@ -68,20 +68,7 @@ impl RegistrationChain {
6868 ) ;
6969 }
7070
71- // Checks that a new registration doesn't contain a signing key that was used by any
72- // other chain. Returns a list of public keys in the registration.
73- for role in cip509. all_roles ( ) {
74- if let Some ( key) = cip509. signing_pk_for_role ( role) {
75- if let Some ( previous) = state. chain_catalyst_id_from_public_key ( & key) . await ? {
76- if & previous != cat_id {
77- cip509. report ( ) . functional_validation (
78- & format ! ( "An update to {cat_id} registration chain uses the same public key ({key:?}) as {previous} chain" ) ,
79- "It isn't allowed to use role 0 signing (certificate subject public) key in different chains" ,
80- ) ;
81- }
82- }
83- }
84- }
71+ check_signing_pk ( cat_id, cip509, state) . await ?;
8572 }
8673
8774 if cip509. report ( ) . is_problematic ( ) {
@@ -113,7 +100,7 @@ impl RegistrationChain {
113100 ///
114101 /// # Errors
115102 /// - Propagates any I/O or provider-level errors encountered while checking key
116- /// ownership (e.g., database lookup failures).
103+ /// ownership (e.g., database lookup failures).
117104 pub async fn update < State > (
118105 & self ,
119106 cip509 : & Cip509 ,
@@ -143,23 +130,7 @@ impl RegistrationChain {
143130 }
144131 }
145132
146- // Checks that a new registration doesn't contain a signing key that was used by any
147- // other chain. Returns a list of public keys in the registration.
148- {
149- let cat_id = self . catalyst_id ( ) ;
150- for role in cip509. all_roles ( ) {
151- if let Some ( key) = cip509. signing_pk_for_role ( role) {
152- if let Some ( previous) = state. chain_catalyst_id_from_public_key ( & key) . await ? {
153- if & previous != cat_id {
154- cip509. report ( ) . functional_validation (
155- & format ! ( "An update to {cat_id} registration chain uses the same public key ({key:?}) as {previous} chain" ) ,
156- "It isn't allowed to use role 0 signing (certificate subject public) key in different chains" ,
157- ) ;
158- }
159- }
160- }
161- }
162- }
133+ check_signing_pk ( self . catalyst_id ( ) , cip509, state) . await ?;
163134
164135 if cip509. report ( ) . is_problematic ( ) {
165136 Ok ( None )
@@ -453,15 +424,15 @@ impl RegistrationChainInner {
453424
454425 check_validation_signature (
455426 cip509. validation_signature ( ) ,
456- & cip509. raw_aux_data ( ) ,
427+ cip509. raw_aux_data ( ) ,
457428 signing_pk,
458429 cip509. report ( ) ,
459430 context,
460431 ) ;
461432
462433 if cip509. txn_inputs_hash ( ) . is_none ( ) {
463434 cip509. report ( ) . missing_field ( "txn inputs hash" , context) ;
464- } ;
435+ }
465436
466437 let Some ( purpose) = cip509. purpose ( ) else {
467438 cip509. report ( ) . missing_field ( "purpose" , context) ;
@@ -551,12 +522,11 @@ impl RegistrationChainInner {
551522 }
552523
553524 return Some ( new_inner. update_cause_another_chain ( cip509) ) ;
554- } else {
555- cip509
556- . report ( )
557- . missing_field ( "previous transaction ID" , context) ;
558- return None ;
559525 }
526+ cip509
527+ . report ( )
528+ . missing_field ( "previous transaction ID" , context) ;
529+ return None ;
560530 } ;
561531
562532 // Previous transaction ID in the CIP509 should equal to the current transaction ID
@@ -586,7 +556,7 @@ impl RegistrationChainInner {
586556
587557 if cip509. txn_inputs_hash ( ) . is_none ( ) {
588558 cip509. report ( ) . missing_field ( "txn inputs hash" , context) ;
589- } ;
559+ }
590560
591561 let Some ( purpose) = cip509. purpose ( ) else {
592562 cip509. report ( ) . missing_field ( "purpose" , context) ;
@@ -749,6 +719,32 @@ fn check_validation_signature(
749719 }
750720}
751721
722+ /// Checks that a new registration doesn't contain a signing key that was used by any
723+ /// other chain.
724+ async fn check_signing_pk < State > (
725+ cat_id : & CatalystId ,
726+ cip509 : & Cip509 ,
727+ state : & State ,
728+ ) -> anyhow:: Result < ( ) >
729+ where
730+ State : RBACState ,
731+ {
732+ for role in cip509. all_roles ( ) {
733+ if let Some ( key) = cip509. signing_pk_for_role ( role) {
734+ if let Some ( previous) = state. chain_catalyst_id_from_public_key ( & key) . await ? {
735+ if & previous != cat_id {
736+ cip509. report ( ) . functional_validation (
737+ & format ! ( "An update to {cat_id} registration chain uses the same public key ({key:?}) as {previous} chain" ) ,
738+ "It isn't allowed to use role 0 signing (certificate subject public) key in different chains" ,
739+ ) ;
740+ }
741+ }
742+ }
743+ }
744+
745+ Ok ( ( ) )
746+ }
747+
752748#[ cfg( test) ]
753749mod test {
754750 use catalyst_types:: catalyst_id:: role_index:: RoleId ;
0 commit comments