Closed
Description
Issue
We need to handle the (de)serialization operations more implicitly allowing:
- Avoid handling manually serialize/deserialize operations
- Store non encoded objects in the entities
- Support multiple serialization format (with auto detection)
To do
Step 1: PoC on ProtocolVerificationKey
type with JsonHex
- Replace
HexEncodedProtocolVerificationKey
byProtocolVerificationKey
- Handle smoothly (de)serialize when embedded in other types (e.g.
CertificateMetada
that has a list ofSignerWithStake
)
Step 2: Apply to all other types
- Implement a generic
ProtocolKey<T>
wrapper type of STM types - Avoid hard coding JsonHex encoded cumbersome values in test by centralizing these values in
fake_data
module (except for golden tests) - Update all the crypto entities that use a
HexEncoded
prefix in type. Here is the list:-
pub type HexEncodedSingleSignature = HexEncodedKey;
-
pub type HexEncodedMultiSignature = HexEncodedKey;
-
pub type HexEncodedAgregateVerificationKey = HexEncodedKey;
-
pub type HexEncodedVerificationKey = HexEncodedKey;
-
pub type HexEncodedVerificationKeySignature = HexEncodedKey;
-
pub type HexEncodedOpCert = HexEncodedKey;
-
pub type HexEncodedGenesisSecretKey = HexEncodedKey;
-
pub type HexEncodedGenesisVerificationKey = HexEncodedKey;
-
pub type HexEncodedGenesisSignature = HexEncodedKey;
-
pub type HexEncodedDigest = HexEncodedKey;
-
pub type HexEncodedEraMarkersSecretKey = HexEncodedKey;
-
pub type HexEncodedEraMarkersVerificationKey = HexEncodedKey;
-
pub type HexEncodedEraMarkersSignature = HexEncodedKey;
-
Update methodology
- Move the type alias from
mithril-common::crypto_helper::types::alias
to themithril-common::crypto_helper::types::wrappers
module - Change the type definition to a
ProtocolKey<T>
where T is the concrete stm types that was behind the hex encoded key - Try to compile the workspace to see where the compilation fails
- Update the failing code, most likely by replacing a lot of
to_string
withtry_into
calls, be wary that usingtry_into
return an error that you should handle. - If the code that fails to compile relate to the aggregator database don't forget to add a golden test (for example see the
test_golden_master
in thedatabase::provider::open_message
module).
Later / to design
Step 3: PoC on ProtocolVerificationKey
type with JSONHex/CborHex?
- Implement traits
SerializeJsonHex
/DeserializeJsonHex
with blanket implementation that handles the (de)serialization in json hex - Implement traits
SerializeCborHex
/DeserializeCborHex
with blanket implementation that handles the (de)serialization in cbor hex - Implement traits
SerializeEntity: SerializeJsonHex+SerializeCborHex
/DeserializeEntity: DeserializeJsonHex+DeserializeCborHex
(that handles auto-detection of type when deserializing?) - Do we need to add an extra information in messages/entities with the encoding type or do we auto-detect encoding?