sdk/python: Add pasta curve serialization

This commit is contained in:
x
2026-01-02 13:45:15 +00:00
parent ad677b0fd9
commit 09bf42ef01

View File

@@ -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<u8> {
darkfi_serial::serialize(&self.0)
}
#[staticmethod]
fn deserialize(data: &[u8]) -> PyResult<Self> {
darkfi_serial::deserialize(data)
.map(Self)
.map_err(|e| PyErr::new::<pyo3::exceptions::PyValueError, _>(e.to_string()))
}
fn __str__(&self) -> PyResult<String> {
Ok(format!("{:?}", self.0))
}
@@ -206,6 +217,17 @@ macro_rules! impl_point {
Self(<$inner>::from(p.0))
}
fn serialize(&self) -> Vec<u8> {
darkfi_serial::serialize(&self.0)
}
#[staticmethod]
fn deserialize(data: &[u8]) -> PyResult<Self> {
darkfi_serial::deserialize(data)
.map(Self)
.map_err(|e| PyErr::new::<pyo3::exceptions::PyValueError, _>(e.to_string()))
}
fn __str__(slf: &Bound<Self>) -> PyResult<String> {
let affine = <$affine>::from_projective(slf);
let (x, y) = affine.coordinates();