Skip to content

Conversation

alessandrokonrad
Copy link
Contributor

This reduces a little bit of overhead in Js with the usage of Buffer.

Copy link
Contributor

@rooooooooob rooooooooob left a comment

Choose a reason for hiding this comment

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

We should figure out #263 before we merge a PR like this.

to_bytes!($name);
from_bytes!($name);
to_hex!($name);
from_hex!($name);
Copy link
Contributor

Choose a reason for hiding this comment

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

@alessandrokonrad Which format should we be using here for hex? The raw bytes? or the CBOR bytes? Currently from_bytes() can return one of those depending on which types. Most types are CBOR bytes, but Addresses, crypto keys and hashes are all raw bytes. See: #263

What is your thoughts on this? I proposed having to_raw_bytes() and to_cbor_bytes() but then if we add in hex to this too that's a lot of variants.

Copy link
Contributor Author

@alessandrokonrad alessandrokonrad Dec 14, 2021

Choose a reason for hiding this comment

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

Which format should we be using here for hex? The raw bytes? or the CBOR bytes?

to_hex/from_hex are simply wrappers around to_bytes/from_bytes. So it returns/takes whatever that is. The macro to_from_bytes is implemented for types that are fully in CBOR I think. I'm not sure how these would look like in raw bytes, for instance Value?

Most types are CBOR bytes, but Addresses, crypto keys and hashes are all raw bytes

I think it makes sense to return them in a format how the cardano ledger would take them, so probably as it is right now. Everything else would be more confusing.
Would to_cbor_bytes simply add a tag in front of the raw bytes, that says something is bytes?

Copy link
Contributor

Choose a reason for hiding this comment

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

Would to_cbor_bytes simply add a tag in front of the raw bytes, that says something is bytes?

In the cases of the hashes/keys and addresses, yes. They're all defined in the .cddl as address = bytes (usually with size limits) for example. When they're used in the context of the CDDL CBOR encoding (e.g. when composed into the other CBOR structures in that spec) they need to have those extra bytes. This is related to our discussion in cardano-foundation/CIPs#148 which going by how the spec is written would need those bytes, which is something that we might want to change there. Either way it's a bit confusing IMO having these two notions of what a byte representation means and I'm not sure about the best way to go about it, which is why I opened up #263.

I think it makes sense to return them in a format how the cardano ledger would take them, so probably as it is right now

If we stay with this we should at least document it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is related to our discussion in cardano-foundation/CIPs#148 which going by how the spec is written would need those bytes, which is something that we might want to change there

Yes I would be for a change there. Or we add a simple helper function in either the message signing library or the serialization-lib to add a tag in front of the raw bytes.

@SebastienGllmt
Copy link
Contributor

Just as a historical note, the reason why we didn't add small utility functions like this is because projects like Yoroi Mobile rely on native bindings to the Rust code. We tried to minimize the amount of time spent on native bindings by trying to have a single way to do things in the Rust side

@vsubhuman vsubhuman added this to the 10.1.0 milestone Feb 18, 2022
@vsubhuman vsubhuman requested a review from lisicky May 13, 2022 12:31
@vsubhuman vsubhuman modified the milestones: 10.1.0, 10.2.0 May 19, 2022
Copy link
Contributor

@lisicky lisicky left a comment

Choose a reason for hiding this comment

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

/check

@vsubhuman vsubhuman changed the base branch from master to hex July 29, 2022 18:58
@vsubhuman vsubhuman changed the base branch from hex to hex-target July 29, 2022 19:02
@vsubhuman
Copy link
Contributor

Pulling this into a local branch so we can work on upgrading it

@vsubhuman vsubhuman merged commit 851f982 into Emurgo:hex-target Jul 29, 2022
@vsubhuman
Copy link
Contributor

Thank you, @alessandrokonrad !

@vsubhuman vsubhuman mentioned this pull request Sep 29, 2022
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants