diff --git a/src/sdk/python/src/pasta.rs b/src/sdk/python/src/pasta.rs index b6857257f..34a96d5bd 100644 --- a/src/sdk/python/src/pasta.rs +++ b/src/sdk/python/src/pasta.rs @@ -27,7 +27,7 @@ use pyo3::{ basic::CompareOp, pyclass, pyfunction, pymethods, types::{PyAnyMethods, PyModule, PyModuleMethods, PyStringMethods, PyTypeMethods}, - wrap_pyfunction, Bound, PyResult, + wrap_pyfunction, Bound, PyErr, PyResult, }; use rand::rngs::OsRng; @@ -99,6 +99,17 @@ macro_rules! impl_elem { Self(self.0.square()) } + fn serialize(&self) -> Vec { + darkfi_serial::serialize(&self.0) + } + + #[staticmethod] + fn deserialize(data: &[u8]) -> PyResult { + darkfi_serial::deserialize(data) + .map(Self) + .map_err(|e| PyErr::new::(e.to_string())) + } + fn __str__(&self) -> PyResult { Ok(format!("{:?}", self.0)) } @@ -206,6 +217,17 @@ macro_rules! impl_point { Self(<$inner>::from(p.0)) } + fn serialize(&self) -> Vec { + darkfi_serial::serialize(&self.0) + } + + #[staticmethod] + fn deserialize(data: &[u8]) -> PyResult { + darkfi_serial::deserialize(data) + .map(Self) + .map_err(|e| PyErr::new::(e.to_string())) + } + fn __str__(slf: &Bound) -> PyResult { let affine = <$affine>::from_projective(slf); let (x, y) = affine.coordinates();