Skip to content

fix(rust/signed-doc): Apply new DocType #347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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/catalyst-types/src/uuid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ use minicbor::data::Tag;
pub const INVALID_UUID: uuid::Uuid = uuid::Uuid::from_bytes([0x00; 16]);

/// UUID CBOR tag <https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml/>.
#[allow(dead_code)]
const UUID_CBOR_TAG: u64 = 37;
pub const UUID_CBOR_TAG: u64 = 37;

/// Uuid validation errors, which could occur during decoding or converting to
/// `UuidV4` or `UuidV7` types.
Expand Down
2 changes: 1 addition & 1 deletion rust/catalyst-types/src/uuid/uuid_v4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use uuid::Uuid;
use super::{decode_cbor_uuid, encode_cbor_uuid, CborContext, UuidError, INVALID_UUID};

/// Type representing a `UUIDv4`.
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, serde::Serialize)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, serde::Serialize)]
pub struct UuidV4(Uuid);

impl UuidV4 {
Expand Down
38 changes: 38 additions & 0 deletions rust/signed_doc/src/doc_types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
//! An implementation of different defined document types
//! <https://input-output-hk.github.io/catalyst-libs/architecture/08_concepts/signed_doc/types/>

use std::sync::LazyLock;

use catalyst_types::uuid::Uuid;

use crate::DocType;

/// Proposal document `UuidV4` type.
pub const PROPOSAL_DOCUMENT_UUID_TYPE: Uuid =
Uuid::from_u128(0x7808_D2BA_D511_40AF_84E8_C0D1_625F_DFDC);
Expand Down Expand Up @@ -53,3 +57,37 @@ pub const IMMUTABLE_LEDGER_BLOCK_UUID_TYPE: Uuid =
Uuid::from_u128(0xD9E7_E6CE_2401_4D7D_9492_F4F7_C642_41C3);
/// Submission Action `UuidV4` type.
pub const SUBMISSION_ACTION: Uuid = Uuid::from_u128(0x7892_7329_CFD9_4EA1_9C71_0E01_9B12_6A65);

// -------- Mapping old document types to new document types --------
// <https://github.com/input-output-hk/catalyst-libs/blob/main/docs/src/architecture/08_concepts/signed_doc/types.md#document-types>

/// Map proposal document type to new doc type list.
#[allow(clippy::expect_used)]
pub static PROPOSAL_DOC_TYPE: LazyLock<DocType> = LazyLock::new(|| {
let ids = &[PROPOSAL_DOCUMENT_UUID_TYPE];
ids.to_vec()
.try_into()
.expect("Failed to convert proposal document Uuid to DocType")
});

/// Map proposal comment document type to new doc type list.
#[allow(clippy::expect_used)]
pub static PROPOSAL_COMMENT_DOC: LazyLock<DocType> = LazyLock::new(|| {
let ids = &[COMMENT_DOCUMENT_UUID_TYPE, PROPOSAL_DOCUMENT_UUID_TYPE];
ids.to_vec()
.try_into()
.expect("Failed to convert proposal comment document Uuid to DocType")
});

/// Map proposal action document type to new doc type list.
#[allow(clippy::expect_used)]
pub static PROPOSAL_ACTION_DOC: LazyLock<DocType> = LazyLock::new(|| {
let ids = &[
PROPOSAL_ACTION_DOCUMENT_UUID_TYPE,
PROPOSAL_DOCUMENT_UUID_TYPE,
SUBMISSION_ACTION,
];
ids.to_vec()
.try_into()
.expect("Failed to convert proposal action document Uuid to DocType")
});
13 changes: 9 additions & 4 deletions rust/signed_doc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub use catalyst_types::{
};
pub use content::Content;
use coset::{CborSerializable, Header, TaggedCborSerializable};
use decode_context::{CompatibilityPolicy, DecodeContext};
pub use metadata::{
ContentEncoding, ContentType, DocType, DocumentRef, ExtraFields, Metadata, Section,
};
Expand Down Expand Up @@ -88,11 +89,11 @@ impl From<InnerCatalystSignedDocument> for CatalystSignedDocument {
impl CatalystSignedDocument {
// A bunch of getters to access the contents, or reason through the document, such as.

/// Return Document Type `UUIDv4`.
/// Return Document Type `DocType` - List of `UUIDv4`.
///
/// # Errors
/// - Missing 'type' field.
pub fn doc_type(&self) -> anyhow::Result<UuidV4> {
pub fn doc_type(&self) -> anyhow::Result<&DocType> {
self.inner.metadata.doc_type()
}

Expand Down Expand Up @@ -238,8 +239,12 @@ impl Decode<'_, ()> for CatalystSignedDocument {
minicbor::decode::Error::message(format!("Invalid COSE Sign document: {e}"))
})?;

let report = ProblemReport::new(PROBLEM_REPORT_CTX);
let metadata = Metadata::from_protected_header(&cose_sign.protected, &report);
let mut report = ProblemReport::new(PROBLEM_REPORT_CTX);
let mut ctx = DecodeContext {
compatibility_policy: CompatibilityPolicy::Accept,
report: &mut report,
};
let metadata = Metadata::from_protected_header(&cose_sign.protected, &mut ctx);
let signatures = Signatures::from_cose_sig_list(&cose_sign.signatures, &report);

let content = if let Some(payload) = cose_sign.payload {
Expand Down
Loading
Loading