@@ -22,6 +22,7 @@ use catalyst_types::{
2222 uuid:: UuidV4 ,
2323} ;
2424use cbork_utils:: decode_helper:: { decode_bytes, decode_helper, decode_map_len} ;
25+ use ed25519_dalek:: VerifyingKey ;
2526use minicbor:: {
2627 decode:: { self } ,
2728 Decode , Decoder ,
@@ -32,6 +33,7 @@ use uuid::Uuid;
3233
3334use crate :: cardano:: cip509:: {
3435 decode_context:: DecodeContext ,
36+ extract_key,
3537 rbac:: Cip509RbacMetadata ,
3638 types:: { PaymentHistory , TxInputHash , ValidationSignature } ,
3739 utils:: Cip0134UriSet ,
@@ -40,7 +42,7 @@ use crate::cardano::cip509::{
4042 validate_txn_inputs_hash,
4143 } ,
4244 x509_chunks:: X509Chunks ,
43- Payment , PointTxnIdx , RoleData ,
45+ C509Cert , LocalRefInt , Payment , PointTxnIdx , RoleData , SimplePublicKeyType , X509DerCert ,
4446} ;
4547
4648/// A x509 metadata envelope.
@@ -227,6 +229,46 @@ impl Cip509 {
227229 self . metadata . as_ref ( ) . and_then ( |m| m. role_data . get ( & role) )
228230 }
229231
232+ /// Returns signing public key for a role.
233+ #[ must_use]
234+ pub fn signing_pk_for_role (
235+ & self ,
236+ role : RoleId ,
237+ ) -> Option < VerifyingKey > {
238+ self . metadata . as_ref ( ) . and_then ( |m| {
239+ let key_ref = m. role_data . get ( & role) . and_then ( |d| d. signing_key ( ) ) ?;
240+ match key_ref. local_ref {
241+ LocalRefInt :: X509Certs => {
242+ m. x509_certs . get ( key_ref. key_offset ) . and_then ( |c| {
243+ if let X509DerCert :: X509Cert ( c) = c {
244+ extract_key:: x509_key ( & c) . ok ( )
245+ } else {
246+ None
247+ }
248+ } )
249+ } ,
250+ LocalRefInt :: C509Certs => {
251+ m. c509_certs . get ( key_ref. key_offset ) . and_then ( |c| {
252+ if let C509Cert :: C509Certificate ( c) = c {
253+ extract_key:: c509_key ( & c) . ok ( )
254+ } else {
255+ None
256+ }
257+ } )
258+ } ,
259+ LocalRefInt :: PubKeys => {
260+ m. pub_keys . get ( key_ref. key_offset ) . and_then ( |c| {
261+ if let SimplePublicKeyType :: Ed25519 ( c) = c {
262+ Some ( c. clone ( ) )
263+ } else {
264+ None
265+ }
266+ } )
267+ } ,
268+ }
269+ } )
270+ }
271+
230272 /// Returns a purpose of this registration.
231273 #[ must_use]
232274 pub fn purpose ( & self ) -> Option < UuidV4 > {
0 commit comments