Re-implement serialization (#201)

* Serialization tests now pass again

* Tidy up and test more edge-cases

* Use attributes rather than custom serializer for arrays

* Add JSON Schema support

* Tests for JSON Schema generation and validation

* Add comments

* Support custom predicates

* Clippy fixes

* Make deserialization/constructor functions pub(crate)
This commit is contained in:
Rob Knight 2025-04-22 04:19:20 -07:00 committed by GitHub
parent 26a6b2d143
commit bf6d8aee8b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 554 additions and 255 deletions

View file

@ -5,10 +5,8 @@ use std::{collections::HashMap, convert::From, fmt};
use anyhow::{anyhow, Result};
use itertools::Itertools;
use serde::{Deserialize, Serialize};
// use schemars::JsonSchema;
// use serde::{Deserialize, Serialize};
use crate::middleware::{
self, check_st_tmpl, hash_str, AnchoredKey, Key, MainPodInputs, NativeOperation,
NativePredicate, OperationAux, OperationType, Params, PodId, PodProver, PodSigner, Predicate,
@ -17,8 +15,10 @@ use crate::middleware::{
mod custom;
mod operation;
mod serialization;
pub use custom::*;
pub use operation::*;
use serialization::*;
/// This type is just for presentation purposes.
#[derive(Clone, Debug, Default, PartialEq, Eq)]
@ -66,8 +66,8 @@ impl SignedPodBuilder {
/// SignedPod is a wrapper on top of backend::SignedPod, which additionally stores the
/// string<-->hash relation of the keys.
#[derive(Debug, Clone)]
// #[serde(try_from = "SignedPodHelper", into = "SignedPodHelper")]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(try_from = "SignedPodHelper", into = "SignedPodHelper")]
pub struct SignedPod {
pub pod: Box<dyn middleware::Pod>,
// We store a copy of the key values for quick access
@ -591,8 +591,8 @@ impl MainPodBuilder {
}
}
#[derive(Debug, Clone)]
// #[serde(try_from = "MainPodHelper", into = "MainPodHelper")]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(try_from = "MainPodHelper", into = "MainPodHelper")]
pub struct MainPod {
pub pod: Box<dyn middleware::Pod>,
pub public_statements: Vec<Statement>,