Skip to content

Commit 61381e4

Browse files
bkioshnMr-Leshiyapskhemno30bitcong-or
authored
feat(rust/signed-doc): Implement new Catalyst Signed Doc (#338)
* chore: add new line to open pr Signed-off-by: bkioshn <[email protected]> * chore: revert Signed-off-by: bkioshn <[email protected]> * feat(rust/signed-doc): add new type `DocType` (#339) * feat(signed-doc): add new type DocType Signed-off-by: bkioshn <[email protected]> * fix(signed-doc): add conversion policy Signed-off-by: bkioshn <[email protected]> * fix(signed-doc): doc type Signed-off-by: bkioshn <[email protected]> * fix(signed-doc): doc type error Signed-off-by: bkioshn <[email protected]> * fix(signed-doc): seperate test Signed-off-by: bkioshn <[email protected]> * fix(signed-doc): format Signed-off-by: bkioshn <[email protected]> --------- Signed-off-by: bkioshn <[email protected]> * feat(rust/signed-doc): Add initial decoding tests for the Catalyst Signed Documents (#349) * wip * wip * fix fmt * fix spelling * fix clippy * fix(rust/signed-doc): Apply new `DocType` (#347) * feat(signed-doc): add new type DocType Signed-off-by: bkioshn <[email protected]> * wip: apply doctype Signed-off-by: bkioshn <[email protected]> * fix(signed-doc): add more function to DocType Signed-off-by: bkioshn <[email protected]> * fix(signed-doc): map old doctype to new doctype Signed-off-by: bkioshn <[email protected]> * fix(signed-doc): add eq to uuidv4 Signed-off-by: bkioshn <[email protected]> * fix(signed-doc): fix validator Signed-off-by: bkioshn <[email protected]> * fix(signed-doc): minor fixes Signed-off-by: bkioshn <[email protected]> * fix(catalyst-types): add hash to uuidv4 Signed-off-by: bkioshn <[email protected]> * fix(signed-doc): decoding test Signed-off-by: bkioshn <[email protected]> * fix(signed-doc): doctype Signed-off-by: bkioshn <[email protected]> * fix(signed-doc): minor fixes Signed-off-by: bkioshn <[email protected]> * chore(sign-doc): fix comment Signed-off-by: bkioshn <[email protected]> * fix(catalyst-types): add fromstr to uuidv4 and 7 Signed-off-by: bkioshn <[email protected]> * fix(signed-doc): restructure doctypes Signed-off-by: bkioshn <[email protected]> * fix(signed-doc): test Signed-off-by: bkioshn <[email protected]> * Update rust/signed_doc/tests/proposal.rs * Update rust/signed_doc/tests/comment.rs * Update rust/signed_doc/tests/submission.rs --------- Signed-off-by: bkioshn <[email protected]> Co-authored-by: Alex Pozhylenkov <[email protected]> * fix(rust/signed-doc): Correct CBOR content type and data validation (#350) * feat: initial * test: minor check * test: more test * fix: minor * Update rust/signed_doc/src/validator/rules/content_type.rs Co-authored-by: Alex Pozhylenkov <[email protected]> * chore: remove proptest * chore: cleanup * chore: split json and cbor * chore: minor adjustment * Update rust/signed_doc/src/validator/rules/content_type.rs Co-authored-by: Artur Helmanau <[email protected]> * fix: import json raw value --------- Co-authored-by: Alex Pozhylenkov <[email protected]> Co-authored-by: Artur Helmanau <[email protected]> * feat(rust/signed-doc): enum map representation for metadata (#359) * feat: metadata enum map representation * add encode/decode impl for Metadata * fix integer label, upd its doc * upd integer label doc. * use ProblemReport, remove map ord decode validation * Update rust/signed_doc/src/metadata/mod.rs * feat(rust/signed-doc): Catalyst signed document encoding using minicbor (#353) * wip * wip * wip * wip * wip * fix * fix clippy * wip * cleanup * wip * wip * wip * wip * wip * wip * wip * update test * fix spelling * wip * wip * Update rust/signed_doc/src/lib.rs Co-authored-by: Artur Helmanau <[email protected]> * Revert "wip" This reverts commit 5b209bb. * fix clippy --------- Co-authored-by: Artur Helmanau <[email protected]> * feat(rust/cbork): deterministic map decoding helper (#360) * feat(deterministic decoder): rfc template WIP * fix: implement minimal length validation for string types Adds validation for minimal length encoding of string types (Str and Bytes) in the DeterministicDecoder according to RFC 8949 Section 4.2. This ensures that string lengths are encoded using the minimal number of bytes required. For example, strings of length 0-23 must use direct encoding, length 24-255 must use one byte, etc. The changes: - Add length validation for Type::Str and Type::Bytes - Check for indefinite length strings - Validate minimal length encoding using check_minimal_length function * test: expand deterministic CBOR decoding tests Adds comprehensive test coverage for RFC 8949 Section 4.2 deterministic encoding requirements. The new tests verify: - Minimal length integer encoding rules for values 0-23, 24-255, etc. - Floating point value requirements including shortest form and non-finite prohibition - String/array/map length encoding rules and indefinite length checks - Map key ordering rules with length-first canonical ordering Each test includes detailed comments explaining: - The specific RFC requirement being tested - Byte-level breakdown of CBOR encodings - Why each test case is valid or invalid - References to relevant RFC sections This ensures proper validation of all deterministic encoding rules and helps maintainers understand the requirements. * cbor: Add comprehensive tests for deterministic encoding Add detailed test cases for deterministic CBOR encoding rules as specified in RFC 8949 section 4.2. The new tests cover: - Integer boundary conditions and minimal encoding requirements - Negative integer encoding across different ranges - Map key ordering (length-first, then lexicographic) - Floating point encoding with different precision requirements - String comparison ordering including UTF-8 handling - Nested structure validation - Array length encoding rules - Duplicate map key detection The tests are extensively documented with RFC requirements and include TODOs for future validation improvements, particularly for floating point handling where additional checks for non-finite values and minimal encoding could be added. Includes commented-out test cases that can be enabled once support for validating non-finite floating point values is implemented. RFC: https://datatracker.ietf.org/doc/html/rfc8949#section-4.2 * cbor: Fix clippy warnings in deterministic tests Refactor test cases to fix clippy warnings: - Use simpler iterator chaining in array length test - Remove redundant calls - Replace explicit type annotations with inferred types - Fix collect() with redundant map operations Also simplify floating point test cases to match current implementation and improve RFC 8949 compliance documentation. The floating point tests now focus on valid encodings while keeping commented-out future test cases for non-finite values validation. Tests still verify the same RFC requirements but with more idiomatic Rust code. * fmt * docs * docs: enhance CBOR deterministic validation documentation Improve documentation and refactor validate_next() to align with RFC 8949 § 4.2 specification for deterministically encoded CBOR. Split validation logic into smaller, focused functions for better maintainability. - Split validate_next into specialized validation functions: * validate_integer() - Handles minimal integer encoding * validate_array() - Validates definite-length arrays * validate_string() - Checks string/bytes encoding * validate_map() - Ensures proper key ordering - Add comprehensive documentation referencing RFC 8949: * Detail core deterministic encoding requirements * Document rules for integer minimality * Explain length field constraints * Specify map key ordering rules * Include examples of valid/invalid encodings This refactoring improves code organization while maintaining full compliance with the CBOR deterministic encoding specification. The enhanced documentation helps developers understand both implementation details and RFC requirements. * docs: enhance CBOR deterministic validation documentation Improve documentation and refactor validate_next() to align with RFC 8949 § 4.2 specification for deterministically encoded CBOR. Split validation logic into smaller, focused functions for better maintainability. - Split validate_next into specialized validation functions: * validate_integer() - Handles minimal integer encoding * validate_array() - Validates definite-length arrays * validate_string() - Checks string/bytes encoding * validate_map() - Ensures proper key ordering - Add comprehensive documentation referencing RFC 8949: * Detail core deterministic encoding requirements * Document rules for integer minimality * Explain length field constraints * Specify map key ordering rules * Include examples of valid/invalid encodings This refactoring improves code organization while maintaining full compliance with the CBOR deterministic encoding specification. The enhanced documentation helps developers understand both implementation details and RFC requirements. * docs: Add comprehensive documentation for CBOR deterministic validation * Add violation test cases for string comparison ordering * Add violation test cases for string comparison ordering * feat(deterministic cbor): toggle validation * feat(deterministic cbor): toggle validation * feat(deterministic cbor): toggle validation * refactor(generic decoder): helper functions * refactor(generic decoder): helper functions * refactor(generic decoder): helper functions * refactor(deterministic maps): rfc validation * refactor(deterministic maps): rfc validation * refactor(deterministic maps): rfc validation * refactor(deterministic maps): rfc validation * refactor(deterministic maps): rfc validation * refactor(deterministic maps): rfc validation * refactor(deterministic maps): rfc validation * refactor(deterministic maps): rfc validation * refactor(deterministic maps): rfc validation * refactor(deterministic maps): rfc validation * refactor(deterministic maps): rfc validation * refactor(deterministic maps): rfc validation * refactor(deterministic maps): rfc validation * refactor(deterministic maps): rfc validation * refactor(minimal length check): maps only * refactor(minimal length check): maps only * refactor(minimal length check): maps only * refactor(minimal length check): maps only * docs: enhance CBOR deterministic validation documentation * feat(deterministic map decoder only): rfc 8949 * feat(deterministic map decoder only): rfc 8949 * feat(deterministic map decoder only): rfc 8949 * feat(deterministic map decoder only): rfc 8949 * feat(deterministic map decoder only): rfc 8949 * feat(deterministic map decoder only): rfc 8949 * feat(deterministic map decoder only): rfc 8949 * feat(deterministic map decoder only): rfc 8949 * feat(deterministic map decoder only): rfc 8949 * feat(deterministic map decoder only): rfc 8949 * feat(deterministic map decoder only): rfc 8949 * refactor(pr changes): houskeeping * fmt * refactor(pr changes): houskeeping * refactor(pr changes): houskeeping * refactor(pr changes): houskeeping * refactor(pr changes): houskeeping * refactor(cleanup): actual vs declared length helper * refactor(cleanup): actual vs declared length helper * refactor(cleanup): actual vs declared length helper * Add comprehensive MapEntry ordering tests - Test length-first and lexicographic key ordering per RFC 8949 - Verify equality vs ordering distinction for CBOR deterministic encoding - Cover edge cases: empty keys, identical entries, duplicate key scenarios * Add comprehensive MapEntry ordering tests - Test length-first and lexicographic key ordering per RFC 8949 - Verify equality vs ordering distinction for CBOR deterministic encoding - Cover edge cases: empty keys, identical entries, duplicate key scenarios * refactor(err): rm deterministic error type * Update rust/cbork-utils/src/deterministic_helper.rs Co-authored-by: Artur Helmanau <[email protected]> * Fix MapEntry ordering to prioritize length over lexicographic comparison The Ord implementation now compares key_bytes by length first, then lexicographically if lengths are equal. This fixes the failing test case where shorter keys should be ordered before longer keys regardless of byte content. * Update rust/cbork-utils/src/deterministic_helper.rs Co-authored-by: Alex Pozhylenkov <[email protected]> * Update rust/cbork-utils/src/deterministic_helper.rs Co-authored-by: Alex Pozhylenkov <[email protected]> * Update rust/cbork-utils/src/deterministic_helper.rs Co-authored-by: Alex Pozhylenkov <[email protected]> * fmt * fmt * fmt * refactor(rm fn): get bytes * refactor(indefinite length items): laconic * refactor(indefinite length items): laconic --------- Co-authored-by: Artur Helmanau <[email protected]> Co-authored-by: Alex Pozhylenkov <[email protected]> * refactor(rust/signed-doc): Cleanup `Builder`, make `raw_bytes` field non-optional (#369) * wip * wip * wip * wip * wip * cleanup * wip * wip * fix clippy * fix(rust/signed-doc): Update doc type (#365) * fix(signed-doc): log and to value Signed-off-by: bkioshn <[email protected]> * fix(signed-doc): add from doctype to vec uuid Signed-off-by: bkioshn <[email protected]> * fix(signed-doc): add more doc type Signed-off-by: bkioshn <[email protected]> * fix(signed-doc): from doctype for vec string Signed-off-by: bkioshn <[email protected]> * fix(signed-doc): revert Signed-off-by: bkioshn <[email protected]> * fix(signed-doc): revert Signed-off-by: bkioshn <[email protected]> * fix(signed-doc): backward compatible rule Signed-off-by: bkioshn <[email protected]> * fix(signed-doc): remove unused doc type Signed-off-by: bkioshn <[email protected]> * fix(signed-doc): improve static doc types Signed-off-by: bkioshn <[email protected]> * fix(signed-doc): add more doc-types Signed-off-by: bkioshn <[email protected]> --------- Signed-off-by: bkioshn <[email protected]> Co-authored-by: Alex Pozhylenkov <[email protected]> * feat(rust/signed-doc): signed doc metadata serde refactoring (#372) * impl deserialize * refactor from_metadata_fields & remove InnerMetadata * rename visitor * handle aliasing * kebab-case only deserialization for SupportedLabel * cleanup * fmt --------- Co-authored-by: Alex Pozhylenkov <[email protected]> * fix(rust/signed-doc): Modify the `DocumentRef` structure (#355) * fix(signed-doc): wip modify document ref Signed-off-by: bkioshn <[email protected]> * fix(signed-doc): wip doc locator Signed-off-by: bkioshn <[email protected]> * fix(catalyst-types): add more derive to uuidv7 Signed-off-by: bkioshn <[email protected]> * fix(signed-doc): new doc ref structure Signed-off-by: bkioshn <[email protected]> * fix(signed-doc): docrefs to value Signed-off-by: bkioshn <[email protected]> * fix(signed-doc): restructure doctypes Signed-off-by: bkioshn <[email protected]> * fix(signed-doc): format Signed-off-by: bkioshn <[email protected]> * fix(signed-doc): linter Signed-off-by: bkioshn <[email protected]> * fix(signed-doc): remove problem report in encoder Signed-off-by: bkioshn <[email protected]> * fix(signed-doc): linter Signed-off-by: bkioshn <[email protected]> * fix(rust/signed-doc): Apply new document ref and fix validation rules (#368) * fix(signed-doc): wip apply new doc ref Signed-off-by: bkioshn <[email protected]> * fix(signed-doc): apply new doc ref and implement validation rule for doc ref Signed-off-by: bkioshn <[email protected]> * fix(signed-doc): revert doc type change Signed-off-by: bkioshn <[email protected]> * fix(signed-doc): remove problem report in encoder Signed-off-by: bkioshn <[email protected]> * fix(signed-doc): metadata decode Signed-off-by: bkioshn <[email protected]> * chore(signed-doc): revert change Signed-off-by: bkioshn <[email protected]> * test(signed-doc): add docref to decoding test Signed-off-by: bkioshn <[email protected]> * fix(signed-doc): format Signed-off-by: bkioshn <[email protected]> * fix(signed-doc): refactor and improvement Signed-off-by: bkioshn <[email protected]> * fix(signed-doc): refactor Signed-off-by: bkioshn <[email protected]> * test(signed-doc): fix content test Signed-off-by: bkioshn <[email protected]> * test(signed-doc): fix content test Signed-off-by: bkioshn <[email protected]> --------- Signed-off-by: bkioshn <[email protected]> --------- Signed-off-by: bkioshn <[email protected]> * chore(rust/signed-doc): Cleanup Catalyst Signed Document `Builder`, make it type safe, add special test builder (2). (#380) * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * fix * fix * fix clippy * chore(signed-doc): add problem report to doc ref (#378) Signed-off-by: bkioshn <[email protected]> Co-authored-by: Alex Pozhylenkov <[email protected]> * feat(rust/signed-doc): `*_wrong_role` Catalyst Signed Documents integration tests (#381) * more tests * fix spelling * test(rust/signed-doc): Add a test case for invalid params and aliases in protected header (#377) * feat: initial test * chore: minor cleanup * feat: full change * chore: fmtfix * chore: minor lintfix * fix: lintfix * Update rust/signed_doc/tests/decoding.rs Co-authored-by: Alex Pozhylenkov <[email protected]> * Update rust/signed_doc/tests/decoding.rs Co-authored-by: Alex Pozhylenkov <[email protected]> * Update rust/signed_doc/tests/decoding.rs Co-authored-by: Alex Pozhylenkov <[email protected]> * fix: comments * chore: remove signature * chore: minor rename * chore: minor --------- Co-authored-by: Mr-Leshiy <[email protected]> * feat(cat-gateway): tests for minimal valid signed docs (#384) * test(rust/signed-doc): Add valid alias decoding as `parameters` case (#382) * feat: initial * chore: minor * feat: add postcheck * chore: minor assertion * feat(rust/signed-doc): Catalyst Signed Documents `minicbor::Decode` impl (#383) * more tests * add signatures decoding logic * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * fix * wip * remove coset * fix clippy * wip * fix spelling * wip * wip * wip * wip * fix comment * wip * add Collaborators type * wip * wip * fix clippy * fix(rust/signed-doc): Fix an issue to using original bytes for signature verification. (#386) * add special_cbor_cases test * wip * fix * wip * fix * add test cases * fix comments * Update rust/signed_doc/src/builder.rs Co-authored-by: Artur Helmanau <[email protected]> * add comments * wip * fix fmt * fix spelling * clippy * fix spelling --------- Co-authored-by: Artur Helmanau <[email protected]> * test(rust/signed-doc): Add random header for signed doc decoding test cases (#388) * feat: initial * fix: content-type and content-encoding * feat: type, id, ver * feat: missing header case * fix: comments * chore: lintfix * chore(rust/signed-doc): Provided a new `WithCborBytes` type, cleaned `InnerCatalystSignedDoc` structure and signature generation and verification process. (#391) * add WithCborBytes new type * update decoder * wip * fix clippy * wip * fix * test(rust/signed-doc): Add test cases for random kid, invalid COSE tag, and case-insensitive `content_encoding` (#389) * feat: initial * test: add wrong cose tag case * chore: minor name * feat(rust/signed-doc): Add new `ContentType` variants: `Cddl` and `JsonSchema` (#392) * feat: initial * chore: lintfix * feat(rust/signed-doc): Add tests for minimal and full metadata fields (#394) * test(rust/signed-doc): add tests for minimal and full metadata fields * fix(rust/signed-doc): spelling * cleanup --------- Co-authored-by: Mr-Leshiy <[email protected]> * feat(rust/signed-doc): add test cases for valid doc type and content fields (#400) * feat(rust/signed-doc): Add CBOR deterministic `Map` as a separate struct, enable deterministic decoding for the metadata fields. (#396) * move decode_map_deterministically impl into separate mod, provide a dedicated type Map * cleanup * Fix CBOR map minimal length validation timing Capture decoder position before d.map() call to correctly read the map header byte instead of the first key when validating minimal encoding. Fixes test_map_minimal_length_encoding failure. * add `DecodeCtx` struct * wip * wip * wip * replace BtreeMap with HashMap * fixes --------- Co-authored-by: cong-or <[email protected]> * feat(rust/signed-doc): Added more decoding test cases, cleaned up `DecodeContext` (#401) * fix signed_doc_with_random_header_field_case * add signed_doc_with_non_empty_unprotected_headers, signed_doc_with_signatures_non_empty_unprotected_headers test cases * refactor DecodeContext * wip * add new test cases * wip * fix clippy * refactor(rust/signed-doc): Change `collabs` header to `collaborators` (#395) * chore: rename * feat: cat-id decoder * fix: minor sync * chore: minor * fix: bstr * chore: b string --------- Co-authored-by: Alex Pozhylenkov <[email protected]> * feat(rust/signed-doc): Invalid test cases for protected headers (#402) * feat(rust/signed-doc): add test cases for invalid fields in metadata and signature headers * fix(rust/signed-doc): cose signature header can only include one field * feat(rust/signed-doc): Cleanup `DocType`, `DocumentRefs` related test cases (#406) * remove redundant signed_doc_valid_doc_type_from_non_empty_uuid_array, signed_doc_valid_doc_type_from_uuid * wip * wip * wip * wip * fix * fix * wip * wip * wip * wip * feat(rust/cbork): Add deterministically decoding array (#407) * handle indefinite-length arrays in non-deterministic mode * feat: indefinite test cases * feat: verbose test cases * chore: remove recursive tests * chore: lintfix * fix: comments --------- Co-authored-by: cong-or <[email protected]> * feat(rust/signed-doc): `Metadata::to_json` method (#410) * add missing `to_json` method for Metadata * fix docs * wip * wip * fix spelling * fix clippy * feat(rust/signed-doc): Apply deterministic CBOR decoding from `cbork-utils` (#418) * initial * chore: minor name * chore: lintfix * fix: document refs 2 elements * fix: spell * chore: error message * add convinient trait implementations (#423) * feat(rust/signed-doc): Add a function to convert back `DocType` to deprecated UUID (#426) * initial * Update rust/signed_doc/src/metadata/doc_type.rs Co-authored-by: Alex Pozhylenkov <[email protected]> --------- Co-authored-by: Alex Pozhylenkov <[email protected]> * fix(rust/signed-doc): Properly export map_doc_type, to_deprecated_doc_type * feat(rust/signed-doc): Revert back to the original `DocType` format (#434) * wip * wip * wip * Update rust/signed_doc/src/metadata/doc_type.rs Co-authored-by: bkioshn <[email protected]> * fix * wip * wip * fix clippy --------- Co-authored-by: bkioshn <[email protected]> * feat(rust/signed-doc): Add `Deref` implementation for the `DocType` (#439) * add Deref impl for DocType * fix * revert using `tag` for now * feat(rust/signed-doc): Add a function to check deprecated version below v0.04 for a signed doc (#441) * initial * chore: minor comment * wip tests * wip * wip * wip * chore: minor test to check non-deterministic * test: minor * chore: add error doc to the function * chore: fmtfix --------- Co-authored-by: Mr-Leshiy <[email protected]> * feat(rust/signed-doc): Fixing `ParametersRule` validation (#445) * fix issue with adding problem report when everything is fine * fix * fix * wip * wip * fix clippy --------- Signed-off-by: bkioshn <[email protected]> Co-authored-by: Alex Pozhylenkov <[email protected]> Co-authored-by: Apisit Ritruengroj <[email protected]> Co-authored-by: Artur Helmanau <[email protected]> Co-authored-by: cong-or <[email protected]> Co-authored-by: Joaquín Rosales <[email protected]> Co-authored-by: Steven Johnson <[email protected]>
1 parent bd97c6f commit 61381e4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+7293
-2208
lines changed

.config/dictionaries/project.dic

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ ciphertexts
4848
Coap
4949
codegen
5050
codepoints
51-
collabs
5251
coti
5352
coverallsapp
5453
cpus

rust/cardano-blockchain-types/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ workspace = true
2020
[dependencies]
2121
pallas = { version = "0.33.0" }
2222
# pallas-hardano = { version = "0.33.0" }
23-
cbork-utils = { version = "0.0.1", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250724-01" }
24-
catalyst-types = { version = "0.0.4", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250724-01" }
23+
cbork-utils = { version = "0.0.1", path = "../cbork-utils" }
24+
catalyst-types = { version = "0.0.4", path = "../catalyst-types" }
2525

2626
ouroboros = "0.18.4"
2727
tracing = "0.1.41"

rust/cardano-chain-follower/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ mithril-client = { version = "0.12.2", default-features = false, features = [
1919
"full",
2020
"num-integer-backend",
2121
] }
22-
cardano-blockchain-types = { version = "0.0.5", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "cardano-blockchain-types-v0.0.5" }
23-
catalyst-types = { version = "0.0.4", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250724-01" }
22+
23+
cardano-blockchain-types = { version = "0.0.5", path = "../cardano-blockchain-types" }
24+
catalyst-types = { version = "0.0.4", path = "../catalyst-types" }
2425

2526

2627
thiserror = "1.0.69"
@@ -64,7 +65,7 @@ test-log = { version = "0.2.16", default-features = false, features = [
6465
"trace",
6566
] }
6667
clap = "4.5.23"
67-
rbac-registration = { version = "0.0.5", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250724-01" }
68+
rbac-registration = { version = "0.0.5", path = "../rbac-registration" }
6869

6970
# Note, these features are for support of features exposed by dependencies.
7071
[features]

rust/catalyst-types/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "catalyst-types"
3-
version = "0.0.3"
3+
version = "0.0.4"
44
edition.workspace = true
55
license.workspace = true
66
authors.workspace = true

rust/catalyst-types/src/catalyst_id/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,12 @@ impl TryFrom<&[u8]> for CatalystId {
709709
}
710710
}
711711

712+
impl From<&CatalystId> for Vec<u8> {
713+
fn from(value: &CatalystId) -> Self {
714+
value.to_string().into_bytes()
715+
}
716+
}
717+
712718
#[cfg(test)]
713719
mod tests {
714720
use chrono::{DateTime, Utc};

rust/catalyst-types/src/uuid/mod.rs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//! `UUID` types.
22
3-
pub use uuid::Uuid;
3+
pub use uuid::{uuid, Uuid};
44
#[allow(clippy::module_name_repetitions)]
5-
pub use uuid_v4::UuidV4;
5+
pub use uuid_v4::{InvalidUuidV4, ParsingError as UuidV4ParsingError, UuidV4};
66
#[allow(clippy::module_name_repetitions)]
7-
pub use uuid_v7::UuidV7;
7+
pub use uuid_v7::{InvalidUuidV7, ParsingError as UuidV7ParsingError, UuidV7};
88

99
mod uuid_v4;
1010
mod uuid_v7;
@@ -15,21 +15,7 @@ use minicbor::data::Tag;
1515
pub const INVALID_UUID: uuid::Uuid = uuid::Uuid::from_bytes([0x00; 16]);
1616

1717
/// UUID CBOR tag <https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml/>.
18-
#[allow(dead_code)]
19-
const UUID_CBOR_TAG: u64 = 37;
20-
21-
/// Uuid validation errors, which could occur during decoding or converting to
22-
/// `UuidV4` or `UuidV7` types.
23-
#[derive(Debug, Clone, thiserror::Error)]
24-
#[allow(clippy::module_name_repetitions)]
25-
pub enum UuidError {
26-
/// `UUIDv4` invalid error
27-
#[error("'{0}' is not a valid UUIDv4")]
28-
InvalidUuidV4(uuid::Uuid),
29-
/// `UUIDv7` invalid error
30-
#[error("'{0}' is not a valid UUIDv7")]
31-
InvalidUuidV7(uuid::Uuid),
32-
}
18+
pub const UUID_CBOR_TAG: u64 = 37;
3319

3420
/// Context for `CBOR` encoding and decoding
3521
pub enum CborContext {
Lines changed: 56 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
//! `UUIDv4` Type.
2-
use std::fmt::{Display, Formatter};
2+
use std::{
3+
fmt::{Display, Formatter},
4+
str::FromStr,
5+
};
36

47
use minicbor::{Decode, Decoder, Encode};
58
use uuid::Uuid;
69

7-
use super::{decode_cbor_uuid, encode_cbor_uuid, CborContext, UuidError, INVALID_UUID};
10+
use super::{decode_cbor_uuid, encode_cbor_uuid, CborContext};
811

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

16+
/// `UUIDv4` invalid error
17+
#[derive(Debug, Clone, thiserror::Error)]
18+
#[error("'{0}' is not a valid UUIDv4")]
19+
pub struct InvalidUuidV4(uuid::Uuid);
20+
1321
impl UuidV4 {
1422
/// Version for `UUIDv4`.
1523
const UUID_VERSION_NUMBER: usize = 4;
@@ -21,28 +29,28 @@ impl UuidV4 {
2129
Self(Uuid::new_v4())
2230
}
2331

24-
/// Generates a zeroed out `UUIDv4` that can never be valid.
25-
#[must_use]
26-
pub fn invalid() -> Self {
27-
Self(INVALID_UUID)
28-
}
29-
30-
/// Check if this is a valid `UUIDv4`.
31-
#[must_use]
32-
pub fn is_valid(&self) -> bool {
33-
is_valid(&self.uuid())
34-
}
35-
3632
/// Returns the `uuid::Uuid` type.
3733
#[must_use]
3834
pub fn uuid(&self) -> Uuid {
3935
self.0
4036
}
37+
38+
/// A const alternative impl of `TryFrom<Uuid>`
39+
///
40+
/// # Errors
41+
/// - `InvalidUuidV4`
42+
pub const fn try_from_uuid(uuid: Uuid) -> Result<Self, InvalidUuidV4> {
43+
if is_valid(&uuid) {
44+
Ok(Self(uuid))
45+
} else {
46+
Err(InvalidUuidV4(uuid))
47+
}
48+
}
4149
}
4250

4351
/// Check if this is a valid `UUIDv4`.
44-
fn is_valid(uuid: &Uuid) -> bool {
45-
uuid != &INVALID_UUID && uuid.get_version_num() == UuidV4::UUID_VERSION_NUMBER
52+
const fn is_valid(uuid: &Uuid) -> bool {
53+
uuid.get_version_num() == UuidV4::UUID_VERSION_NUMBER
4654
}
4755

4856
impl Display for UuidV4 {
@@ -54,13 +62,7 @@ impl Display for UuidV4 {
5462
impl Decode<'_, CborContext> for UuidV4 {
5563
fn decode(d: &mut Decoder<'_>, ctx: &mut CborContext) -> Result<Self, minicbor::decode::Error> {
5664
let uuid = decode_cbor_uuid(d, ctx)?;
57-
if is_valid(&uuid) {
58-
Ok(Self(uuid))
59-
} else {
60-
Err(minicbor::decode::Error::message(UuidError::InvalidUuidV4(
61-
uuid,
62-
)))
63-
}
65+
Self::try_from_uuid(uuid).map_err(minicbor::decode::Error::message)
6466
}
6567
}
6668

@@ -74,14 +76,10 @@ impl Encode<CborContext> for UuidV4 {
7476

7577
/// Returns a `UUIDv4` from `uuid::Uuid`.
7678
impl TryFrom<Uuid> for UuidV4 {
77-
type Error = UuidError;
79+
type Error = InvalidUuidV4;
7880

7981
fn try_from(uuid: Uuid) -> Result<Self, Self::Error> {
80-
if is_valid(&uuid) {
81-
Ok(Self(uuid))
82-
} else {
83-
Err(UuidError::InvalidUuidV4(uuid))
84-
}
82+
Self::try_from_uuid(uuid)
8583
}
8684
}
8785

@@ -98,43 +96,47 @@ impl<'de> serde::Deserialize<'de> for UuidV4 {
9896
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
9997
where D: serde::Deserializer<'de> {
10098
let uuid = Uuid::deserialize(deserializer)?;
101-
if is_valid(&uuid) {
102-
Ok(Self(uuid))
103-
} else {
104-
Err(serde::de::Error::custom(UuidError::InvalidUuidV4(uuid)))
105-
}
99+
Self::try_from_uuid(uuid).map_err(serde::de::Error::custom)
100+
}
101+
}
102+
103+
/// `FromStr` invalid error
104+
#[derive(Debug, Clone, thiserror::Error)]
105+
pub enum ParsingError {
106+
/// `UUIDv4` invalid error
107+
#[error(transparent)]
108+
InvalidUuidV4(#[from] InvalidUuidV4),
109+
/// Invalid string conversion
110+
#[error("Invalid string conversion: {0}")]
111+
StringConversion(String),
112+
}
113+
114+
impl FromStr for UuidV4 {
115+
type Err = ParsingError;
116+
117+
fn from_str(s: &str) -> Result<Self, Self::Err> {
118+
let uuid = Uuid::parse_str(s).map_err(|_| ParsingError::StringConversion(s.to_string()))?;
119+
Ok(Self::try_from_uuid(uuid)?)
106120
}
107121
}
108122

109123
#[cfg(test)]
110124
mod tests {
111125
use super::*;
126+
use crate::uuid::INVALID_UUID;
112127

113128
#[test]
114129
fn test_invalid_uuid() {
115-
let invalid_uuid = UuidV4::invalid();
116-
assert!(!invalid_uuid.is_valid(), "Invalid UUID should not be valid");
117-
assert_eq!(
118-
invalid_uuid.uuid(),
119-
INVALID_UUID,
120-
"Invalid UUID should match INVALID_UUID"
121-
);
122-
}
130+
assert!(UuidV4::try_from(Uuid::now_v7()).is_err());
123131

124-
#[test]
125-
fn test_valid_uuid() {
126-
let valid_uuid = UuidV4::try_from(Uuid::new_v4()).unwrap();
127-
assert!(valid_uuid.is_valid(), "Valid UUID should be valid");
128-
129-
let valid_uuid = UuidV4::new();
130-
assert!(valid_uuid.is_valid(), "Valid UUID should be valid");
131-
}
132-
133-
#[test]
134-
fn test_invalid_version_uuid() {
135132
assert!(
136133
UuidV4::try_from(INVALID_UUID).is_err(),
137134
"Zero UUID should not be valid"
138135
);
139136
}
137+
138+
#[test]
139+
fn test_valid_uuid() {
140+
assert!(UuidV4::try_from(Uuid::new_v4()).is_ok());
141+
}
140142
}

0 commit comments

Comments
 (0)