@@ -17,10 +17,10 @@ pub use builder::Builder;
1717use catalyst_types:: problem_report:: ProblemReport ;
1818pub use content:: Content ;
1919use coset:: { CborSerializable , Header } ;
20- use ed25519_dalek:: VerifyingKey ;
2120use error:: CatalystSignedDocError ;
2221pub use metadata:: { DocumentRef , ExtraFields , Metadata , UuidV4 , UuidV7 } ;
2322pub use minicbor:: { decode, encode, Decode , Decoder , Encode } ;
23+ pub use rbac_registration:: cardano:: cip509:: SimplePublicKeyType ;
2424pub use signature:: { IdUri , Signatures } ;
2525use utils:: context:: DecodeSignDocCtx ;
2626
@@ -131,34 +131,50 @@ impl CatalystSignedDocument {
131131 /// Returns a report of verification failures and the source error.
132132 #[ allow( clippy:: indexing_slicing) ]
133133 pub fn verify < P > ( & self , pk_getter : P ) -> Result < ( ) , CatalystSignedDocError >
134- where P : Fn ( & IdUri ) -> VerifyingKey {
134+ where P : Fn ( & IdUri ) -> SimplePublicKeyType {
135135 let error_report = ProblemReport :: new ( "Catalyst Signed Document Verification" ) ;
136136
137137 match self . as_cose_sign ( ) {
138138 Ok ( cose_sign) => {
139139 let signatures = self . signatures ( ) . cose_signatures ( ) ;
140140 for ( idx, kid) in self . signatures ( ) . kids ( ) . iter ( ) . enumerate ( ) {
141- let pk = pk_getter ( kid) ;
142- let signature = & signatures[ idx] ;
143- let tbs_data = cose_sign. tbs_data ( & [ ] , signature) ;
144- match signature. signature . as_slice ( ) . try_into ( ) {
145- Ok ( signature_bytes) => {
146- let signature = ed25519_dalek:: Signature :: from_bytes ( signature_bytes) ;
147- if let Err ( e) = pk. verify_strict ( & tbs_data, & signature) {
148- error_report. functional_validation (
149- & format ! (
150- "Verification failed for signature with Key ID {kid}: {e}"
151- ) ,
152- "During signature validation with verifying key" ,
153- ) ;
141+ match pk_getter ( kid) {
142+ SimplePublicKeyType :: Ed25519 ( pk) => {
143+ let signature = & signatures[ idx] ;
144+ let tbs_data = cose_sign. tbs_data ( & [ ] , signature) ;
145+ match signature. signature . as_slice ( ) . try_into ( ) {
146+ Ok ( signature_bytes) => {
147+ let signature =
148+ ed25519_dalek:: Signature :: from_bytes ( signature_bytes) ;
149+ if let Err ( e) = pk. verify_strict ( & tbs_data, & signature) {
150+ error_report. functional_validation (
151+ & format ! (
152+ "Verification failed for signature with Key ID {kid}: {e}"
153+ ) ,
154+ "During signature validation with verifying key" ,
155+ ) ;
156+ }
157+ } ,
158+ Err ( _) => {
159+ error_report. invalid_value (
160+ "cose signature" ,
161+ & format ! ( "{}" , signature. signature. len( ) ) ,
162+ & format ! ( "must be {}" , ed25519_dalek:: Signature :: BYTE_SIZE ) ,
163+ "During encoding cose signature to bytes" ,
164+ ) ;
165+ } ,
154166 }
155167 } ,
156- Err ( _) => {
157- error_report. invalid_value (
158- "cose signature" ,
159- & format ! ( "{}" , signature. signature. len( ) ) ,
160- & format ! ( "must be {}" , ed25519_dalek:: Signature :: BYTE_SIZE ) ,
161- "During encoding cose signature to bytes" ,
168+ SimplePublicKeyType :: Deleted => {
169+ error_report. other (
170+ & format ! ( "Public key for {kid} has been deleted." ) ,
171+ "During public key extraction" ,
172+ ) ;
173+ } ,
174+ SimplePublicKeyType :: Undefined => {
175+ error_report. other (
176+ & format ! ( "Public key for {kid} is undefined." ) ,
177+ "During public key extraction" ,
162178 ) ;
163179 } ,
164180 }
@@ -417,6 +433,8 @@ mod tests {
417433 . build ( )
418434 . unwrap ( ) ;
419435
420- assert ! ( signed_doc. verify( |_| { pk } ) . is_ok( ) ) ;
436+ assert ! ( signed_doc
437+ . verify( |_| { SimplePublicKeyType :: Ed25519 ( pk) } )
438+ . is_ok( ) ) ;
421439 }
422440}
0 commit comments