Skip to content

Commit 534e3f5

Browse files
committed
wip
1 parent ac4093c commit 534e3f5

File tree

3 files changed

+171
-215
lines changed

3 files changed

+171
-215
lines changed

rust/rbac-registration/src/cardano/cip509/cip509.rs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use catalyst_types::{
2222
uuid::UuidV4,
2323
};
2424
use cbork_utils::decode_helper::{decode_bytes, decode_helper, decode_map_len};
25+
use ed25519_dalek::VerifyingKey;
2526
use minicbor::{
2627
decode::{self},
2728
Decode, Decoder,
@@ -32,6 +33,7 @@ use uuid::Uuid;
3233

3334
use 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> {

rust/rbac-registration/src/providers.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub trait RbacRegistrationProvider {
1414
/// for the given Catalyst ID.
1515
fn chain(
1616
&self,
17-
id: CatalystId,
17+
id: &CatalystId,
1818
) -> impl Future<Output = anyhow::Result<Option<RegistrationChain>>> + Send;
1919

2020
/// Returns `true` if a chain with the given Catalyst ID already exists.
@@ -24,24 +24,25 @@ pub trait RbacRegistrationProvider {
2424
/// chain.
2525
fn is_chain_known(
2626
&self,
27-
id: CatalystId,
27+
id: &CatalystId,
2828
) -> impl Future<Output = anyhow::Result<bool>> + Send;
2929

30-
/// Returns a Catalyst ID corresponding to the given stake address.
31-
fn catalyst_id_from_stake_address(
30+
/// Returns a current valid registration chain corresponding to the given stake
31+
/// address.
32+
fn chain_from_stake_address(
3233
&self,
3334
address: &StakeAddress,
34-
) -> impl Future<Output = anyhow::Result<Option<CatalystId>>> + Send;
35+
) -> impl Future<Output = anyhow::Result<Option<RegistrationChain>>> + Send;
3536

3637
/// Returns a Catalyst ID corresponding to the given public key.
3738
fn catalyst_id_from_public_key(
3839
&self,
39-
key: VerifyingKey,
40+
key: &VerifyingKey,
4041
) -> impl Future<Output = anyhow::Result<Option<CatalystId>>> + Send;
4142

4243
/// Returns a Catalyst ID corresponding to the given transaction hash.
4344
fn catalyst_id_from_txn_id(
4445
&self,
45-
txn_id: TransactionId,
46+
txn_id: &TransactionId,
4647
) -> impl Future<Output = anyhow::Result<Option<CatalystId>>> + Send;
4748
}

0 commit comments

Comments
 (0)