Module tari_crypto::ristretto::serialize [−][src]
Expand description
Custom serializers for Ristretto keys
The Dalek libraries only serialize to binary (understandably), but this has 2 yucky implications:
- Exporting to “human readable” formats like JSON yield crappy looking ‘binary arrays’, e.g. /[12, 223, 65, …/]
- Reading back from JSON is broken because serde doesn’t read this back as a byte string, but as a seq.
The workaround is to have binary serialization by default, but if a struct is going to be saved in JSON format,
then you can override that behaviour with with_serialize
, e.g.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct KeyManager<K: SecretKey, D: Digest> {
#[serde(serialize_with = "serialise_to_hex", deserialize_with = "secret_from_hex")]
pub master_key: K,
pub branch_seed: String,
pub primary_key_index: usize,
digest_type: PhantomData<D>,
}