fix: consistently serialize signer (#334)
- serialize the signer in base58 both as Value and as the signer embedded in the SignedPod json data field. - Implement serialization/deserialization for Signature
This commit is contained in:
parent
0750dbeaff
commit
aeedf55bad
2 changed files with 31 additions and 33 deletions
|
|
@ -20,16 +20,18 @@ use plonky2::{
|
|||
plonk::circuit_builder::CircuitBuilder,
|
||||
};
|
||||
use rand::rngs::OsRng;
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
|
||||
use super::curve::Point;
|
||||
use crate::{
|
||||
backends::plonky2::{
|
||||
circuits::common::CircuitBuilderPod,
|
||||
deserialize_bytes,
|
||||
primitives::ec::{
|
||||
bits::{BigUInt320Target, CircuitBuilderBits},
|
||||
curve::{CircuitBuilderElliptic, PointTarget, WitnessWriteCurve, GROUP_ORDER},
|
||||
},
|
||||
Error,
|
||||
serialize_bytes, Error,
|
||||
},
|
||||
middleware::RawValue,
|
||||
};
|
||||
|
|
@ -76,6 +78,28 @@ impl Signature {
|
|||
}
|
||||
}
|
||||
|
||||
impl Serialize for Signature {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
let signature_b64 = serialize_bytes(&self.as_bytes());
|
||||
serializer.serialize_str(&signature_b64)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for Signature {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let signature_b64 = String::deserialize(deserializer)?;
|
||||
let signature_bytes =
|
||||
deserialize_bytes(&signature_b64).map_err(serde::de::Error::custom)?;
|
||||
Signature::from_bytes(&signature_bytes).map_err(serde::de::Error::custom)
|
||||
}
|
||||
}
|
||||
|
||||
/// Targets for Schnorr signature over ecGFp5.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct SignatureTarget {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue