Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
3 changes: 1 addition & 2 deletions rust/cardano-blockchain-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ crate-type = ["cdylib", "rlib"]
workspace = true

[dependencies]
catalyst-types = { version = "0.0.6", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "catalyst-types/v0.0.6" }
catalyst-types = { version = "0.0.9", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "catalyst-types/v0.0.9" }
cbork-utils = { version = "0.0.2", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "cbork-utils-v0.0.2" }

ouroboros = "0.18.4"
Expand All @@ -35,7 +35,6 @@ num-traits = "0.2.19"
ed25519-dalek = "2.1.1"
serde = "1.0.210"
num-bigint = "0.4.6"
serde_json = "1.0.134"
displaydoc = "0.2.5"
thiserror = "2.0.11"

Expand Down
49 changes: 6 additions & 43 deletions rust/cardano-blockchain-types/src/metadata/cip36/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl fmt::Display for Cip36 {
) -> fmt::Result {
write!(
f,
"Cip36 {{ network: {network}, slot: {slot:?}, txn_idx: {txn_idx:?}, is_catalyst_strict: {is_catalyst_strict}, key_registration: {key_registration:?}, registration_witness: {registration_witness:?}, validation: {{ signature: {is_valid_signature}, payment_address_network: {is_valid_payment_address_network}, voting_keys: {is_valid_voting_keys}, purpose: {is_valid_purpose} }}, err_report: {err_report} }}",
"Cip36 {{ network: {network}, slot: {slot:?}, txn_idx: {txn_idx:?}, is_catalyst_strict: {is_catalyst_strict}, key_registration: {key_registration:?}, registration_witness: {registration_witness:?}, validation: {{ signature: {is_valid_signature}, payment_address_network: {is_valid_payment_address_network}, voting_keys: {is_valid_voting_keys}, purpose: {is_valid_purpose} }}, problematic: {is_problematic} }}",
key_registration = self.key_registration,
registration_witness = self.registration_witness,
network = self.network,
Expand All @@ -62,34 +62,7 @@ impl fmt::Display for Cip36 {
is_valid_payment_address_network = self.is_valid_payment_address_network,
is_valid_voting_keys = self.is_valid_voting_keys,
is_valid_purpose = self.is_valid_purpose,
err_report = serde_json::to_string(&self.err_report)
.unwrap_or_else(|_| String::from("Failed to serialize ProblemReport"))
)
}
}

/// CIP-36 Catalyst registration error
#[allow(dead_code, clippy::module_name_repetitions)]
#[derive(Debug)]
pub struct Cip36Error {
/// The decoding error that make the code not able to process.
error: anyhow::Error,
/// The problem report that contains the errors found during decoding and validation.
report: ProblemReport,
}

impl fmt::Display for Cip36Error {
fn fmt(
&self,
fmt: &mut fmt::Formatter<'_>,
) -> fmt::Result {
let report_json = serde_json::to_string(&self.report)
.unwrap_or_else(|_| String::from("Failed to serialize ProblemReport"));

write!(
fmt,
"Cip36Error {{ error: {}, report: {} }}",
self.error, report_json
is_problematic = self.err_report.is_problematic(),
)
}
}
Expand Down Expand Up @@ -118,7 +91,7 @@ impl Cip36 {
block: &MultiEraBlock,
txn_idx: TxnIndex,
is_catalyst_strict: bool,
) -> Result<Option<Cip36>, Cip36Error> {
) -> anyhow::Result<Option<Cip36>> {
// Record of errors found during decoding and validation
let mut err_report = ProblemReport::new("CIP36 Registration Decoding and Validation");

Expand Down Expand Up @@ -148,25 +121,15 @@ impl Cip36 {
metadata
},
Err(e) => {
return Err(Cip36Error {
error: anyhow::anyhow!(format!(
"Failed to construct CIP-36 key registration, {e}"
)),
report: err_report,
});
anyhow::bail!("Failed to construct CIP-36 key registration, {e}");
},
};

let registration_witness =
match Cip36RegistrationWitness::decode(&mut registration_witness, &mut err_report) {
Ok(metadata) => metadata,
Err(e) => {
return Err(Cip36Error {
error: anyhow::anyhow!(format!(
"Failed to construct CIP-36 registration witness {e}"
)),
report: err_report,
});
anyhow::bail!("Failed to construct CIP-36 registration witness {e}");
},
};

Expand Down Expand Up @@ -210,7 +173,7 @@ impl Cip36 {
pub fn cip36_from_block(
block: &MultiEraBlock,
is_catalyst_strict: bool,
) -> Option<HashMap<TxnIndex, Result<Cip36, Cip36Error>>> {
) -> Option<HashMap<TxnIndex, anyhow::Result<Cip36>>> {
let mut cip36_map = HashMap::new();

for (txn_idx, _tx) in block.decode().txs().iter().enumerate() {
Expand Down
4 changes: 2 additions & 2 deletions rust/cardano-chain-follower/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cardano-chain-follower"
version = "0.0.16"
version = "0.0.17"
edition.workspace = true
authors.workspace = true
homepage.workspace = true
Expand All @@ -17,7 +17,7 @@ mithril-client = { version = "=0.12.2", default-features = false, features = [
] }

cardano-blockchain-types = { version = "0.0.7", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "cardano-blockchain-types/v0.0.7" }
catalyst-types = { version = "0.0.8", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "catalyst-types/v0.0.8" }
catalyst-types = { version = "0.0.9", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "catalyst-types/v0.0.9" }

thiserror = "1.0.69"
tokio = { version = "1.45.0", features = [
Expand Down
4 changes: 2 additions & 2 deletions rust/rbac-registration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "rbac-registration"
description = "Role Based Access Control Registration"
keywords = ["cardano", "catalyst", "rbac registration"]
version = "0.0.12"
version = "0.0.13"
authors = [
"Arissara Chotivichit <arissara.chotivichit@iohk.io>"
]
Expand Down Expand Up @@ -35,4 +35,4 @@ thiserror = "2.0.11"
c509-certificate = { version = "0.0.3", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "c509-certificate-v0.0.3" }
cbork-utils = { version = "0.0.2", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "cbork-utils-v0.0.2" }
cardano-blockchain-types = { version = "0.0.7", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "cardano-blockchain-types/v0.0.7" }
catalyst-types = { version = "0.0.8", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "catalyst-types/v0.0.8" }
catalyst-types = { version = "0.0.9", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "catalyst-types/v0.0.9" }
4 changes: 2 additions & 2 deletions rust/signed_doc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "catalyst-signed-doc"
version = "0.0.8"
version = "0.0.9"
edition.workspace = true
authors.workspace = true
homepage.workspace = true
Expand All @@ -11,7 +11,7 @@ license.workspace = true
workspace = true

[dependencies]
catalyst-types = { version = "0.0.8", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "catalyst-types/v0.0.8" }
catalyst-types = { version = "0.0.9", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "catalyst-types/v0.0.9" }
cbork-utils = { version = "0.0.2", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "cbork-utils-v0.0.2" }

catalyst-signed-doc-macro = { version = "0.0.1", path = "../catalyst-signed-doc-macro" }
Expand Down
19 changes: 5 additions & 14 deletions rust/signed_doc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ impl Display for CatalystSignedDocument {
if self.inner.signatures.is_empty() {
writeln!(f, " This document is unsigned.")?;
} else {
for kid in &self.kids() {
writeln!(f, " Signature Key ID: {kid}")?;
for kid in &self.authors() {
writeln!(f, " Author ID: {kid}")?;
}
}
Ok(())
Expand Down Expand Up @@ -161,23 +161,14 @@ impl CatalystSignedDocument {
&self.inner.signatures
}

/// Return a list of Document's Catalyst IDs.
#[must_use]
pub fn kids(&self) -> Vec<CatalystId> {
self.inner
.signatures
.iter()
.map(|s| s.kid().clone())
.collect()
}

/// Return a list of Document's author IDs (short form of Catalyst IDs).
/// Return a list of Document's Signer's Catalyst IDs,
#[must_use]
pub fn authors(&self) -> Vec<CatalystId> {
self.inner
.signatures
.iter()
.map(|s| s.kid().as_short_id())
.map(|s| s.kid())
.cloned()
.collect()
}

Expand Down
17 changes: 2 additions & 15 deletions rust/signed_doc/src/validator/rules/ownership/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use catalyst_signed_doc_spec::{
signers::update::{Update, UpdatersType},
DocSpec,
};
use catalyst_types::catalyst_id::CatalystId;

use crate::{providers::CatalystSignedDocumentProvider, CatalystSignedDocument};

Expand Down Expand Up @@ -105,13 +104,7 @@ impl DocumentOwnershipRule {
"A latest version of the document must exist if a first version exists"
))?;

allowed_authors.extend(
last_doc
.doc_meta()
.collaborators()
.iter()
.map(CatalystId::as_short_id),
);
allowed_authors.extend(last_doc.doc_meta().collaborators().iter().cloned());
}
},
Self::RefFieldBased => {
Expand Down Expand Up @@ -141,13 +134,7 @@ impl DocumentOwnershipRule {
"A latest version of the document must exist if a first version exists"
))?;

allowed_authors.extend(
last_doc
.doc_meta()
.collaborators()
.iter()
.map(CatalystId::as_short_id),
);
allowed_authors.extend(last_doc.doc_meta().collaborators().iter().cloned());
},
}

Expand Down
2 changes: 1 addition & 1 deletion rust/signed_doc/src/validator/rules/signature_kid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl SignatureKidRule {
&self,
doc: &CatalystSignedDocument,
) -> anyhow::Result<bool> {
let contains_exp_role = doc.kids().iter().enumerate().all(|(i, kid)| {
let contains_exp_role = doc.authors().iter().enumerate().all(|(i, kid)| {
let (role_index, _) = kid.role_and_rotation();
let res = self.allowed_roles.contains(&role_index);
if !res {
Expand Down
2 changes: 1 addition & 1 deletion rust/signed_doc/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub fn get_doc_kid_and_sk(
doc: &CatalystSignedDocument,
i: usize,
) -> anyhow::Result<(ed25519_dalek::SigningKey, CatalystId)> {
let doc_kids = doc.kids();
let doc_kids = doc.authors();
let kid = doc_kids
.get(i)
.ok_or(anyhow::anyhow!("does not have a kid at index '{i}'"))?;
Expand Down
10 changes: 5 additions & 5 deletions rust/signed_doc/tests/decoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ fn signed_doc_with_minimal_metadata_fields_case() -> TestCase {
anyhow::ensure!(
doc.encoded_content() == serde_json::to_vec(&serde_json::Value::Null)?
);
anyhow::ensure!(doc.kids().len() == 1);
anyhow::ensure!(doc.authors().len() == 1);
anyhow::ensure!(!doc.is_deprecated()?);
Ok(())
}
Expand Down Expand Up @@ -673,7 +673,7 @@ fn signed_doc_with_complete_metadata_fields_case() -> TestCase {
anyhow::ensure!(doc.doc_meta().reply() == Some(&refs));
anyhow::ensure!(doc.doc_content_type() == Some(ContentType::Json));
anyhow::ensure!(doc.encoded_content() == serde_json::to_vec(&serde_json::Value::Null)?);
anyhow::ensure!(doc.kids().len() == 1);
anyhow::ensure!(doc.authors().len() == 1);
anyhow::ensure!(!doc.is_deprecated()?);
Ok(())
}
Expand Down Expand Up @@ -1138,7 +1138,7 @@ fn signed_doc_with_non_strict_deterministic_decoding_wrong_order() -> TestCase {
anyhow::ensure!(
doc.encoded_content() == serde_json::to_vec(&serde_json::Value::Null)?
);
anyhow::ensure!(doc.kids().len() == 1);
anyhow::ensure!(doc.authors().len() == 1);
Ok(())
}
})),
Expand Down Expand Up @@ -1197,7 +1197,7 @@ fn signed_doc_with_non_supported_metadata_invalid() -> TestCase {
anyhow::ensure!(
doc.encoded_content() == serde_json::to_vec(&serde_json::Value::Null)?
);
anyhow::ensure!(doc.kids().len() == 0);
anyhow::ensure!(doc.authors().len() == 0);
Ok(())
}
})),
Expand Down Expand Up @@ -1265,7 +1265,7 @@ fn signed_doc_with_kid_in_id_form_invalid() -> TestCase {
anyhow::ensure!(
doc.encoded_content() == serde_json::to_vec(&serde_json::Value::Null)?
);
anyhow::ensure!(doc.kids().len() == 1);
anyhow::ensure!(doc.authors().len() == 1);
Ok(())
}
})),
Expand Down
Loading