Skip to content

feat(rust/signed-doc): Catalyst signed document encoding using minicbor #353

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 24 commits into from
Jun 17, 2025

Conversation

Mr-Leshiy
Copy link
Contributor

@Mr-Leshiy Mr-Leshiy commented May 30, 2025

Description

Partially migrating signed-doc components encoding from coset to minicbor.

As the next step, COSE helpers from #351 are intended to be salvaged too.

Related Issue(s)

Closes #332

Description of Changes

  • Refactored ContentType, ContentEncoding, DocumentRef, Section and other signed-doc components to minicbor.
  • The existing coset traits now wrap around the minicibor implementation as opposed to the other way around it's been before.
  • serde implementations, which coset depends on through ciborium, now also made to wrap the minicbor implementation where possible.

Breaking Changes

None.

Related Pull Requests

Please confirm the following checks

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream module

@Mr-Leshiy Mr-Leshiy changed the title feat(rust/signed-doc): feat(rust/signed-doc): Catalyst signed document encoding using minicbor May 30, 2025
@Mr-Leshiy Mr-Leshiy changed the base branch from main to feat/new-cat-signed-doc May 30, 2025 08:06
coset::ContentType::Assigned(CoapContentFormat::Cbor) => ContentType::Cbor,
_ => {
match value {
coset::ContentType::Assigned(CoapContentFormat::Json) => Ok(ContentType::Json),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The aim is to remove coset, is it not?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inside this PR, I've just removing coset for encoding functionality. Decoding would be done under the different PR

@@ -12,10 +12,11 @@ pub(crate) mod utils;
use catalyst_types::{problem_report::ProblemReport, uuid::UuidV7};
pub use content_encoding::ContentEncoding;
pub use content_type::ContentType;
use coset::{cbor::Value, iana::CoapContentFormat, CborSerializable};
use coset::CborSerializable;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't use coset at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be eliminated under the next PR

@Mr-Leshiy Mr-Leshiy marked this pull request as ready for review June 16, 2025 12:34
@Mr-Leshiy Mr-Leshiy requested a review from no30bit June 16, 2025 14:13
@Mr-Leshiy Mr-Leshiy requested a review from stevenj June 16, 2025 18:09
@Mr-Leshiy Mr-Leshiy self-assigned this Jun 16, 2025
@Mr-Leshiy Mr-Leshiy added the review me PR is ready for review label Jun 16, 2025
fn encode<W: minicbor::encode::Write>(
&self, e: &mut minicbor::Encoder<W>, _ctx: &mut (),
) -> Result<(), minicbor::encode::Error<W::Error>> {
e.str(self.to_string().as_str())?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we figure out what's up with the mismatch between Section spec and its impl?

Catalyst specRFC6901 Standard JSON Pointer.
Impl in this fileRFC9535 JSONPath.

I've brought up this issue before, but it hasn't been resolved. Either the spec or the impl should change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create pls a separate ticket under this feature ticket, #330.
Under this PR, not going to change it, just keep the original behaviour that we have

| SupportedField::Parameters(document_ref) => document_ref.encode(e, ctx),
SupportedField::Type(doc_type) => doc_type.encode(e, ctx),
SupportedField::Collabs(collabs) => {
if !collabs.is_empty() {
Copy link
Contributor

@no30bit no30bit Jun 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the cddl spec be changed from

collaborators = [ * catalyst_id_kid ]

to

collaborators = [ + catalyst_id_kid ]

Because it's not deterministic encoding if this field is both optional and can be an empty array. This impl follows the optional + rule.

<minicbor::bytes::ByteVec>::from(minicbor::to_vec(metadata)?),
<minicbor::bytes::ByteVec>::from(protected_header_bytes(kid)?),
minicbor::bytes::ByteArray::from([]),
<minicbor::bytes::ByteVec>::from(content.encoded_bytes(metadata.content_encoding())?),
Copy link
Contributor

@no30bit no30bit Jun 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neither Catalyst spec nor RFC 8152 Section 2 explicitly says whether an empty payload should nil or empty bstr. RFC says – nil if the signature is for a detached content.

From what I understand, it wouldn't make sense for Catalyst Singed Document to have a detached content signature.

So could the spec be changed to forbid nil? This impl follows that rule.

Mr-Leshiy and others added 3 commits June 17, 2025 13:39
Copy link
Contributor

Test Report | ${\color{lightgreen}Pass: 337/337}$ | ${\color{red}Fail: 0/337}$ |

Copy link
Contributor

@no30bit no30bit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Mr-Leshiy Mr-Leshiy merged commit c0d22c6 into feat/new-cat-signed-doc Jun 17, 2025
24 checks passed
@Mr-Leshiy Mr-Leshiy deleted the feat/minicbor-encoding branch June 17, 2025 14:26
@no30bit no30bit mentioned this pull request Jun 18, 2025
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review me PR is ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants