Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions rust/cardano-blockchain-types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "cardano-blockchain-types"
description = "Common Cardano Blockchain data types for use in both applications and crates"
keywords = ["cardano", "catalyst",]
keywords = ["cardano", "catalyst", ]
version = "0.0.1"
authors = [
"Steven Johnson <[email protected]>"
Expand All @@ -20,8 +20,8 @@ workspace = true
[dependencies]
pallas = { version = "0.30.1", git = "https://github.com/input-output-hk/catalyst-pallas.git", rev = "9b5183c8b90b90fe2cc319d986e933e9518957b3" }
# pallas-hardano = { version = "0.30.1", git = "https://github.com/input-output-hk/catalyst-pallas.git", rev = "9b5183c8b90b90fe2cc319d986e933e9518957b3" }
cbork-utils = { version = "0.0.1", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "v0.0.11" }
catalyst-types = { version = "0.0.1", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250108-00" }
cbork-utils = { version = "0.0.1", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250127-00" }
catalyst-types = { version = "0.0.1", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250127-00" }

ouroboros = "0.18.4"
tracing = "0.1.41"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
//! <https://cips.cardano.org/cip/CIP-36>
//! <https://github.com/cardano-foundation/CIPs/blob/master/CIP-0036/schema.cddl>

use catalyst_types::problem_report::ProblemReport;
use catalyst_types::{
cbor_utils::{report_duplicated_key, report_missing_keys},
problem_report::ProblemReport,
};
use cbork_utils::decode_helper::{decode_array_len, decode_bytes, decode_helper, decode_map_len};
use ed25519_dalek::VerifyingKey;
use minicbor::{decode, Decode, Decoder};
Expand Down Expand Up @@ -88,7 +91,13 @@ impl Decode<'_, ProblemReport> for Cip36KeyRegistration {
let key: u16 = decode_helper(d, "key in CIP36 Key Registration", err_report)?;

if let Some(key) = Cip36KeyRegistrationKeys::from_repr(key) {
if check_is_key_exist(&found_keys, &key, index, err_report) {
if report_duplicated_key(
&found_keys,
&key,
index,
"CIP36 Key Registration",
err_report,
) {
continue;
}
match key {
Expand Down Expand Up @@ -127,37 +136,17 @@ impl Decode<'_, ProblemReport> for Cip36KeyRegistration {
Cip36KeyRegistrationKeys::PaymentAddr,
Cip36KeyRegistrationKeys::Nonce,
];

for key in &required_keys {
if !found_keys.contains(key) {
err_report.missing_field(
&format!("{key:?}"),
"Missing required key in CIP36 Key Registration",
);
}
}
report_missing_keys(
&found_keys,
&required_keys,
"CIP36 Key Registration",
err_report,
);

Ok(cip36_key_registration)
}
}

/// Helper function for checking whether the key is already in the `found_keys` or not.
/// True if exist, false if not.
fn check_is_key_exist(
found_keys: &[Cip36KeyRegistrationKeys], key: &Cip36KeyRegistrationKeys, index: u64,
err_report: &ProblemReport,
) -> bool {
if found_keys.contains(key) {
err_report.duplicate_field(
format!("{key:?}").as_str(),
format!("Redundant key found in item {} in RBAC map", index + 1).as_str(),
format!("CIP36 Key Registration {key:?}").as_str(),
);
return true;
}
false
}

/// Helper function for decoding the voting key.
///
/// # Returns
Expand Down
19 changes: 19 additions & 0 deletions rust/cardano-blockchain-types/src/metadata/cip36/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,71 +227,85 @@ impl Cip36 {

/// Get the `is_cip36` flag from the registration.
/// True if it is CIP-36 format, false if CIP-15 format.
#[must_use]
pub fn is_cip36(&self) -> Option<bool> {
self.key_registration.is_cip36
}

/// Get the voting public keys from the registration.
#[must_use]
pub fn voting_pks(&self) -> &Vec<VotingPubKey> {
&self.key_registration.voting_pks
}

/// Get the stake public key from the registration.
#[must_use]
pub fn stake_pk(&self) -> Option<&VerifyingKey> {
self.key_registration.stake_pk.as_ref()
}

/// Get the payment address from the registration.
#[must_use]
pub fn payment_address(&self) -> Option<&ShelleyAddress> {
self.key_registration.payment_addr.as_ref()
}

/// Get the nonce from the registration.
#[must_use]
pub fn nonce(&self) -> Option<u64> {
self.key_registration.nonce
}

/// Get the purpose from the registration.
#[must_use]
pub fn purpose(&self) -> u64 {
self.key_registration.purpose
}

/// Get the raw nonce from the registration.
#[must_use]
pub fn raw_nonce(&self) -> Option<u64> {
self.key_registration.raw_nonce
}

/// Is the payment address in the registration payable?
#[must_use]
pub fn is_payable(&self) -> Option<bool> {
self.key_registration.is_payable
}

/// Get the signature from the registration witness.
#[must_use]
pub fn signature(&self) -> Option<ed25519_dalek::Signature> {
self.registration_witness.signature
}

/// Get the slot number of this CIP-36 registration.
#[must_use]
pub fn slot(&self) -> Slot {
self.slot
}

/// Get the network of this CIP-36 registration.
#[must_use]
pub fn network(&self) -> Network {
self.network
}

/// Get the transaction index of this CIP-36 registration.
#[must_use]
pub fn txn_idx(&self) -> TxnIndex {
self.txn_idx
}

/// Get the Catalyst strict flag.
#[must_use]
pub fn is_strict_catalyst(&self) -> bool {
self.is_catalyst_strict
}

/// Is the CIP-36 registration valid?
#[must_use]
pub fn is_valid(&self) -> bool {
// Check everything
self.is_valid_signature
Expand All @@ -302,26 +316,31 @@ impl Cip36 {
}

/// Is the signature valid?
#[must_use]
pub fn is_valid_signature(&self) -> bool {
self.is_valid_signature
}

/// Is the payment address network tag match the provided network?
#[must_use]
pub fn is_valid_payment_address_network(&self) -> bool {
self.is_valid_payment_address_network
}

/// Is the voting keys valid?
#[must_use]
pub fn is_valid_voting_keys(&self) -> bool {
self.is_valid_voting_keys
}

/// Is the purpose valid?
#[must_use]
pub fn is_valid_purpose(&self) -> bool {
self.is_valid_purpose
}

/// Get the error report.
#[must_use]
pub fn err_report(&self) -> &ProblemReport {
&self.err_report
}
Expand Down
6 changes: 3 additions & 3 deletions rust/rbac-registration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ uuid = "1.11.0"

c509-certificate = { version = "0.0.3", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "v0.0.3" }
pallas = { version = "0.30.1", git = "https://github.com/input-output-hk/catalyst-pallas.git", rev = "9b5183c8b90b90fe2cc319d986e933e9518957b3" }
cbork-utils = { version = "0.0.1", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250124-00" }
cardano-blockchain-types = { version = "0.0.1", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250124-00" }
catalyst-types = { version = "0.0.1", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250124-00" }
cbork-utils = { version = "0.0.1", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250127-00" }
cardano-blockchain-types = { version = "0.0.1", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250127-00" }
catalyst-types = { version = "0.0.1", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250127-00" }
25 changes: 12 additions & 13 deletions rust/rbac-registration/src/cardano/cip509/cip509.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::{borrow::Cow, collections::HashMap};
use anyhow::{anyhow, Context};
use cardano_blockchain_types::{MetadatumLabel, MultiEraBlock, TxnIndex};
use catalyst_types::{
cbor_utils::{report_duplicated_key, report_missing_keys},
hashes::{Blake2b256Hash, BLAKE_2B256_SIZE},
problem_report::ProblemReport,
uuid::UuidV4,
Expand All @@ -28,19 +29,16 @@ use strum_macros::FromRepr;
use tracing::warn;
use uuid::Uuid;

use crate::{
cardano::cip509::{
decode_context::DecodeContext,
rbac::Cip509RbacMetadata,
types::{PaymentHistory, RoleNumber, TxInputHash, ValidationSignature},
utils::Cip0134UriSet,
validation::{
validate_aux, validate_role_data, validate_stake_public_key, validate_txn_inputs_hash,
},
x509_chunks::X509Chunks,
Payment, PointTxnIdx, RoleData,
use crate::cardano::cip509::{
decode_context::DecodeContext,
rbac::Cip509RbacMetadata,
types::{PaymentHistory, RoleNumber, TxInputHash, ValidationSignature},
utils::Cip0134UriSet,
validation::{
validate_aux, validate_role_data, validate_stake_public_key, validate_txn_inputs_hash,
},
utils::decode_helper::{report_duplicated_key, report_missing_keys},
x509_chunks::X509Chunks,
Payment, PointTxnIdx, RoleData,
};

/// A x509 metadata envelope.
Expand Down Expand Up @@ -294,7 +292,8 @@ impl Decode<'_, DecodeContext<'_, '_>> for Cip509 {
// Consume the key. This should never fail because we used `probe` above.
let _: u8 = decode_helper(d, context, &mut ())?;

if report_duplicated_key(&found_keys, &key, index, context, decode_context.report) {
if report_duplicated_key(&found_keys, &key, index, "Cip509", decode_context.report)
{
continue;
}
found_keys.push(key);
Expand Down
23 changes: 13 additions & 10 deletions rust/rbac-registration/src/cardano/cip509/rbac/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@

use std::collections::{HashMap, HashSet};

use catalyst_types::problem_report::ProblemReport;
use catalyst_types::{cbor_utils::report_duplicated_key, problem_report::ProblemReport};
use cbork_utils::decode_helper::{
decode_any, decode_array_len, decode_bytes, decode_helper, decode_map_len,
};
use minicbor::{decode, Decode, Decoder};
use strum_macros::FromRepr;

use crate::{
cardano::cip509::{
decode_context::DecodeContext,
rbac::{role_data::CborRoleData, C509Cert, SimplePublicKeyType, X509DerCert},
utils::Cip0134UriSet,
CertKeyHash, RoleData, RoleNumber,
},
utils::decode_helper::report_duplicated_key,
use crate::cardano::cip509::{
decode_context::DecodeContext,
rbac::{role_data::CborRoleData, C509Cert, SimplePublicKeyType, X509DerCert},
utils::Cip0134UriSet,
CertKeyHash, RoleData, RoleNumber,
};

/// Cip509 RBAC metadata.
Expand Down Expand Up @@ -94,7 +91,13 @@ impl Decode<'_, DecodeContext<'_, '_>> for Cip509RbacMetadata {
for index in 0..map_len {
let key: u16 = decode_helper(d, "key in Cip509RbacMetadata", &mut ())?;
if let Some(key) = Cip509RbacMetadataInt::from_repr(key) {
if report_duplicated_key(&found_keys, &key, index, context, decode_context.report) {
if report_duplicated_key(
&found_keys,
&key,
index,
"Cip509RbacMetadata",
decode_context.report,
) {
continue;
}
found_keys.push(key);
Expand Down
12 changes: 6 additions & 6 deletions rust/rbac-registration/src/cardano/cip509/rbac/role_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

use std::collections::HashMap;

use catalyst_types::problem_report::ProblemReport;
use catalyst_types::{
cbor_utils::{report_duplicated_key, report_missing_keys},
problem_report::ProblemReport,
};
use cbork_utils::decode_helper::{decode_any, decode_array_len, decode_helper, decode_map_len};
use minicbor::{decode, Decode, Decoder};
use strum_macros::FromRepr;

use crate::{
cardano::cip509::{KeyLocalRef, RoleNumber},
utils::decode_helper::{report_duplicated_key, report_missing_keys},
};
use crate::cardano::cip509::{KeyLocalRef, RoleNumber};

/// Role data as encoded in CBOR.
#[allow(clippy::module_name_repetitions)]
Expand Down Expand Up @@ -61,7 +61,7 @@ impl Decode<'_, ProblemReport> for CborRoleData {
for index in 0..map_len {
let key: u8 = decode_helper(d, "key in RoleData", &mut ())?;
if let Some(key) = RoleDataInt::from_repr(key) {
if report_duplicated_key(&found_keys, &key, index, context, report) {
if report_duplicated_key(&found_keys, &key, index, "RoleData", report) {
continue;
}
found_keys.push(key);
Expand Down
33 changes: 0 additions & 33 deletions rust/rbac-registration/src/utils/decode_helper.rs

This file was deleted.

2 changes: 0 additions & 2 deletions rust/rbac-registration/src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
//! Utility functions for the RBAC registration module.

pub mod decode_helper;

#[cfg(test)]
pub mod test;
Loading