mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-07 22:04:03 -05:00
sdk/python: Add pasta curve serialization
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user