@@ -20,11 +20,11 @@ use catalyst_types::problem_report::ProblemReport;
2020pub use catalyst_types:: uuid:: { UuidV4 , UuidV7 } ;
2121pub use content:: Content ;
2222use coset:: { CborSerializable , Header } ;
23- use ed25519_dalek:: VerifyingKey ;
2423use error:: CatalystSignedDocError ;
2524pub use metadata:: { DocumentRef , ExtraFields , Metadata } ;
2625pub use minicbor:: { decode, encode, Decode , Decoder , Encode } ;
27- pub use signature:: { KidUri , Signatures } ;
26+ pub use rbac_registration:: cardano:: cip509:: SimplePublicKeyType ;
27+ pub use signature:: { IdUri , Signatures } ;
2828use utils:: context:: DecodeSignDocCtx ;
2929
3030/// Inner type that holds the Catalyst Signed Document with parsing errors.
@@ -110,41 +110,74 @@ impl CatalystSignedDocument {
110110 & self . inner . signatures
111111 }
112112
113+ /// Return a list of Document's Catalyst IDs.
114+ #[ must_use]
115+ pub fn kids ( & self ) -> Vec < IdUri > {
116+ self . inner . signatures . kids ( )
117+ }
118+
119+ /// Return a list of Document's author IDs (short form of Catalyst IDs).
120+ #[ must_use]
121+ pub fn authors ( & self ) -> Vec < IdUri > {
122+ self . inner
123+ . signatures
124+ . kids ( )
125+ . into_iter ( )
126+ . map ( |k| k. as_short_id ( ) )
127+ . collect ( )
128+ }
129+
113130 /// Verify document signatures.
114131 ///
115132 /// # Errors
116133 ///
117134 /// Returns a report of verification failures and the source error.
118135 #[ allow( clippy:: indexing_slicing) ]
119136 pub fn verify < P > ( & self , pk_getter : P ) -> Result < ( ) , CatalystSignedDocError >
120- where P : Fn ( & KidUri ) -> VerifyingKey {
137+ where P : Fn ( & IdUri ) -> SimplePublicKeyType {
121138 let error_report = ProblemReport :: new ( "Catalyst Signed Document Verification" ) ;
122139
123140 match self . as_cose_sign ( ) {
124141 Ok ( cose_sign) => {
125142 let signatures = self . signatures ( ) . cose_signatures ( ) ;
126- for ( idx, kid) in self . signatures ( ) . kids ( ) . iter ( ) . enumerate ( ) {
127- let pk = pk_getter ( kid) ;
128- let signature = & signatures[ idx] ;
129- let tbs_data = cose_sign. tbs_data ( & [ ] , signature) ;
130- match signature. signature . as_slice ( ) . try_into ( ) {
131- Ok ( signature_bytes) => {
132- let signature = ed25519_dalek:: Signature :: from_bytes ( signature_bytes) ;
133- if let Err ( e) = pk. verify_strict ( & tbs_data, & signature) {
134- error_report. functional_validation (
135- & format ! (
136- "Verification failed for signature with Key ID {kid}: {e}"
137- ) ,
138- "During signature validation with verifying key" ,
139- ) ;
143+ for ( idx, kid) in self . kids ( ) . iter ( ) . enumerate ( ) {
144+ match pk_getter ( kid) {
145+ SimplePublicKeyType :: Ed25519 ( pk) => {
146+ let signature = & signatures[ idx] ;
147+ let tbs_data = cose_sign. tbs_data ( & [ ] , signature) ;
148+ match signature. signature . as_slice ( ) . try_into ( ) {
149+ Ok ( signature_bytes) => {
150+ let signature =
151+ ed25519_dalek:: Signature :: from_bytes ( signature_bytes) ;
152+ if let Err ( e) = pk. verify_strict ( & tbs_data, & signature) {
153+ error_report. functional_validation (
154+ & format ! (
155+ "Verification failed for signature with Key ID {kid}: {e}"
156+ ) ,
157+ "During signature validation with verifying key" ,
158+ ) ;
159+ }
160+ } ,
161+ Err ( _) => {
162+ error_report. invalid_value (
163+ "cose signature" ,
164+ & format ! ( "{}" , signature. signature. len( ) ) ,
165+ & format ! ( "must be {}" , ed25519_dalek:: Signature :: BYTE_SIZE ) ,
166+ "During encoding cose signature to bytes" ,
167+ ) ;
168+ } ,
140169 }
141170 } ,
142- Err ( _) => {
143- error_report. invalid_value (
144- "cose signature" ,
145- & format ! ( "{}" , signature. signature. len( ) ) ,
146- & format ! ( "must be {}" , ed25519_dalek:: Signature :: BYTE_SIZE ) ,
147- "During encoding cose signature to bytes" ,
171+ SimplePublicKeyType :: Deleted => {
172+ error_report. other (
173+ & format ! ( "Public key for {kid} has been deleted." ) ,
174+ "During public key extraction" ,
175+ ) ;
176+ } ,
177+ SimplePublicKeyType :: Undefined => {
178+ error_report. other (
179+ & format ! ( "Public key for {kid} is undefined." ) ,
180+ "During public key extraction" ,
148181 ) ;
149182 } ,
150183 }
@@ -389,11 +422,11 @@ mod tests {
389422 let pk = sk. verifying_key ( ) ;
390423
391424 let kid_str = format ! (
392- "kid .catalyst-rbac ://cardano/{}/0/0" ,
425+ "id .catalyst://cardano/{}/0/0" ,
393426 base64_url:: encode( pk. as_bytes( ) )
394427 ) ;
395428
396- let kid = KidUri :: from_str ( & kid_str) . unwrap ( ) ;
429+ let kid = IdUri :: from_str ( & kid_str) . unwrap ( ) ;
397430 let ( _, _, metadata) = test_metadata ( ) . unwrap ( ) ;
398431 let signed_doc = Builder :: new ( )
399432 . with_decoded_content ( content)
@@ -404,13 +437,15 @@ mod tests {
404437 . unwrap ( ) ;
405438
406439 assert ! ( signed_doc
407- . verify( |k| {
408- if k. to_string( ) == kid. to_string( ) {
409- pk
410- } else {
411- k. role0_pk( )
412- }
413- } )
440+ . verify( |_| { SimplePublicKeyType :: Ed25519 ( pk) } )
414441 . is_ok( ) ) ;
442+
443+ assert ! ( signed_doc
444+ . verify( |_| { SimplePublicKeyType :: Undefined } )
445+ . is_err( ) ) ;
446+
447+ assert ! ( signed_doc
448+ . verify( |_| { SimplePublicKeyType :: Deleted } )
449+ . is_err( ) ) ;
415450 }
416451}
0 commit comments