From be900653a80e3570300f5a126af98660ab59a7d2 Mon Sep 17 00:00:00 2001
From: Piotr Roslaniec
Date: Mon, 10 Jul 2023 12:06:18 +0200
Subject: [PATCH] fix: python typings don't match runtime
---
.github/workflows/workspace.yml | 8 ++-
Pipfile | 11 ++++
ferveo-python/Cargo.toml | 1 -
ferveo-python/Pipfile | 11 ++++
ferveo-python/examples/exception.py | 2 +-
.../examples/server_api_precomputed.py | 2 +-
ferveo-python/examples/server_api_simple.py | 2 +-
ferveo-python/ferveo/__init__.py | 2 +-
ferveo-python/ferveo/__init__.pyi | 65 ++++++++++---------
ferveo-python/pyproject.toml | 26 ++++----
ferveo-python/src/lib.rs | 2 +-
ferveo-python/test/test_ferveo.py | 2 +-
ferveo-python/test/test_serialization.py | 2 +-
ferveo/src/bindings_python.rs | 1 +
14 files changed, 84 insertions(+), 53 deletions(-)
create mode 100644 Pipfile
create mode 100644 ferveo-python/Pipfile
diff --git a/.github/workflows/workspace.yml b/.github/workflows/workspace.yml
index 04be31b8..e14f8e2a 100644
--- a/.github/workflows/workspace.yml
+++ b/.github/workflows/workspace.yml
@@ -175,13 +175,17 @@ jobs:
run: python examples/server_api_simple.py
working-directory: ferveo-python
- - name: Install pytest
- run: pip install pytest
+ - name: Install pip dependencies
+ run: pip install pytest mypy
- name: Run pytest
run: pytest
working-directory: ferveo-python
+ - name: Run mypy.stubtest
+ run: python -m mypy.stubtest ferveo
+ working-directory: ferveo-python
+
codecov:
runs-on: ubuntu-latest
needs: [ test ]
diff --git a/Pipfile b/Pipfile
new file mode 100644
index 00000000..c398b0d5
--- /dev/null
+++ b/Pipfile
@@ -0,0 +1,11 @@
+[[source]]
+url = "https://pypi.org/simple"
+verify_ssl = true
+name = "pypi"
+
+[packages]
+
+[dev-packages]
+
+[requires]
+python_version = "3.10"
diff --git a/ferveo-python/Cargo.toml b/ferveo-python/Cargo.toml
index 7fc78583..eafc050c 100644
--- a/ferveo-python/Cargo.toml
+++ b/ferveo-python/Cargo.toml
@@ -8,7 +8,6 @@ publish = false
[lib]
crate-type = ["cdylib"]
-name = "ferveo_py"
[features]
extension-module = ["pyo3/extension-module"]
diff --git a/ferveo-python/Pipfile b/ferveo-python/Pipfile
new file mode 100644
index 00000000..c398b0d5
--- /dev/null
+++ b/ferveo-python/Pipfile
@@ -0,0 +1,11 @@
+[[source]]
+url = "https://pypi.org/simple"
+verify_ssl = true
+name = "pypi"
+
+[packages]
+
+[dev-packages]
+
+[requires]
+python_version = "3.10"
diff --git a/ferveo-python/examples/exception.py b/ferveo-python/examples/exception.py
index a653b43a..4e16aea9 100644
--- a/ferveo-python/examples/exception.py
+++ b/ferveo-python/examples/exception.py
@@ -1,4 +1,4 @@
-from ferveo_py import (
+from ferveo import (
Keypair,
Validator,
Dkg,
diff --git a/ferveo-python/examples/server_api_precomputed.py b/ferveo-python/examples/server_api_precomputed.py
index c0973b66..0916738d 100644
--- a/ferveo-python/examples/server_api_precomputed.py
+++ b/ferveo-python/examples/server_api_precomputed.py
@@ -1,4 +1,4 @@
-from ferveo_py import (
+from ferveo import (
encrypt,
combine_decryption_shares_precomputed,
decrypt_with_shared_secret,
diff --git a/ferveo-python/examples/server_api_simple.py b/ferveo-python/examples/server_api_simple.py
index de26ba38..e41c9f24 100644
--- a/ferveo-python/examples/server_api_simple.py
+++ b/ferveo-python/examples/server_api_simple.py
@@ -1,4 +1,4 @@
-from ferveo_py import (
+from ferveo import (
encrypt,
combine_decryption_shares_simple,
decrypt_with_shared_secret,
diff --git a/ferveo-python/ferveo/__init__.py b/ferveo-python/ferveo/__init__.py
index 43b4bbd6..f89aa778 100644
--- a/ferveo-python/ferveo/__init__.py
+++ b/ferveo-python/ferveo/__init__.py
@@ -1,4 +1,4 @@
-from .ferveo_py import (
+from ._ferveo import (
encrypt,
combine_decryption_shares_simple,
combine_decryption_shares_precomputed,
diff --git a/ferveo-python/ferveo/__init__.pyi b/ferveo-python/ferveo/__init__.pyi
index e16189d1..4d540655 100644
--- a/ferveo-python/ferveo/__init__.pyi
+++ b/ferveo-python/ferveo/__init__.pyi
@@ -1,21 +1,21 @@
-from typing import Sequence
-
+from typing import Sequence, final
+@final
class Keypair:
@staticmethod
def random() -> Keypair:
...
@staticmethod
- def from_secure_randomness(data: bytes) -> Keypair:
+ def from_secure_randomness(bytes: bytes) -> Keypair:
...
@staticmethod
- def secure_randomness_size(data: bytes) -> int:
+ def secure_randomness_size() -> int:
...
@staticmethod
- def from_bytes(data: bytes) -> Keypair:
+ def from_bytes(bytes: bytes) -> Keypair:
...
def __bytes__(self) -> bytes:
@@ -24,10 +24,10 @@ class Keypair:
def public_key(self) -> FerveoPublicKey:
...
-
+@final
class FerveoPublicKey:
@staticmethod
- def from_bytes(data: bytes) -> FerveoPublicKey:
+ def from_bytes(bytes: bytes) -> FerveoPublicKey:
...
def __bytes__(self) -> bytes:
@@ -36,10 +36,11 @@ class FerveoPublicKey:
def __hash__(self) -> int:
...
- def __richcmp__(self, other: FerveoPublicKey, op: int) -> bool:
+ @staticmethod
+ def serialized_size() -> int:
...
-
+@final
class Validator:
def __init__(self, address: str, public_key: FerveoPublicKey):
@@ -49,25 +50,29 @@ class Validator:
public_key: FerveoPublicKey
-
+@final
class Transcript:
@staticmethod
- def from_bytes(data: bytes) -> Transcript:
+ def from_bytes(bytes: bytes) -> Transcript:
...
def __bytes__(self) -> bytes:
...
-
+@final
class DkgPublicKey:
@staticmethod
- def from_bytes(data: bytes) -> DkgPublicKey:
+ def from_bytes(bytes: bytes) -> DkgPublicKey:
...
def __bytes__(self) -> bytes:
...
+ @staticmethod
+ def serialized_size() -> int:
+ ...
+@final
class ValidatorMessage:
def __init__(
@@ -80,7 +85,7 @@ class ValidatorMessage:
validator: Validator
transcript: Transcript
-
+@final
class Dkg:
def __init__(
@@ -101,34 +106,33 @@ class Dkg:
def aggregate_transcripts(self, messages: Sequence[ValidatorMessage]) -> AggregatedTranscript:
...
-
+@final
class Ciphertext:
@staticmethod
- def from_bytes(data: bytes) -> Ciphertext:
+ def from_bytes(bytes: bytes) -> Ciphertext:
...
def __bytes__(self) -> bytes:
...
-
+@final
class DecryptionShareSimple:
@staticmethod
- def from_bytes(data: bytes) -> DecryptionShareSimple:
+ def from_bytes(bytes: bytes) -> DecryptionShareSimple:
...
def __bytes__(self) -> bytes:
...
-
-
+@final
class DecryptionSharePrecomputed:
@staticmethod
- def from_bytes(data: bytes) -> DecryptionSharePrecomputed:
+ def from_bytes(bytes: bytes) -> DecryptionSharePrecomputed:
...
def __bytes__(self) -> bytes:
...
-
+@final
class AggregatedTranscript:
def __init__(self, messages: Sequence[ValidatorMessage]):
@@ -156,23 +160,24 @@ class AggregatedTranscript:
...
@staticmethod
- def from_bytes(data: bytes) -> AggregatedTranscript:
+ def from_bytes(bytes: bytes) -> AggregatedTranscript:
...
def __bytes__(self) -> bytes:
...
-
+@final
class SharedSecret:
@staticmethod
- def from_bytes(data: bytes) -> SharedSecret:
+ def from_bytes(bytes: bytes) -> SharedSecret:
...
def __bytes__(self) -> bytes:
...
+@final
class FerveoVariant:
@staticmethod
def simple() -> str: ...
@@ -181,18 +186,18 @@ class FerveoVariant:
def precomputed() -> str: ...
-def encrypt(message: bytes, add: bytes, dkg_public_key: DkgPublicKey) -> Ciphertext:
+def encrypt(message: bytes, aad: bytes, dkg_public_key: DkgPublicKey) -> Ciphertext:
...
def combine_decryption_shares_simple(
- decryption_shares: Sequence[DecryptionShareSimple],
+ shares: Sequence[DecryptionShareSimple],
) -> bytes:
...
def combine_decryption_shares_precomputed(
- decryption_shares: Sequence[DecryptionSharePrecomputed],
+ shares: Sequence[DecryptionSharePrecomputed],
) -> SharedSecret:
...
@@ -267,7 +272,3 @@ class ValidatorPublicKeyMismatch(Exception):
class SerializationError(Exception):
pass
-
-
-class InvalidVariant(Exception):
- pass
diff --git a/ferveo-python/pyproject.toml b/ferveo-python/pyproject.toml
index a0010648..f90a4e13 100644
--- a/ferveo-python/pyproject.toml
+++ b/ferveo-python/pyproject.toml
@@ -1,14 +1,18 @@
-[build-system]
-requires = ["maturin>=0.14,<0.15"]
-build-backend = "maturin"
+#[build-system]
+#requires = ["maturin>=0.14,<0.15"]
+#build-backend = "maturin"
+#
+#[project]
+#name = "ferveo"
+#requires-python = ">=3.7"
+#classifiers = [
+# "Programming Language :: Rust",
+# "Programming Language :: Python :: Implementation :: CPython",
+# "Programming Language :: Python :: Implementation :: PyPy",
+#]
+#
-[project]
-name = "ferveo"
-requires-python = ">=3.7"
-classifiers = [
- "Programming Language :: Rust",
- "Programming Language :: Python :: Implementation :: CPython",
- "Programming Language :: Python :: Implementation :: PyPy",
-]
+[build-system]
+requires = ["setuptools", "wheel", "setuptools-rust"]
diff --git a/ferveo-python/src/lib.rs b/ferveo-python/src/lib.rs
index fff55e96..71e29c9f 100644
--- a/ferveo-python/src/lib.rs
+++ b/ferveo-python/src/lib.rs
@@ -2,6 +2,6 @@ use ferveo::bindings_python::*;
use pyo3::prelude::*;
#[pymodule]
-fn ferveo_py(py: Python, m: &PyModule) -> PyResult<()> {
+fn _ferveo(py: Python, m: &PyModule) -> PyResult<()> {
make_ferveo_py_module(py, m)
}
diff --git a/ferveo-python/test/test_ferveo.py b/ferveo-python/test/test_ferveo.py
index b92f1c01..b045fec3 100644
--- a/ferveo-python/test/test_ferveo.py
+++ b/ferveo-python/test/test_ferveo.py
@@ -1,6 +1,6 @@
import pytest
-from ferveo_py import (
+from ferveo import (
encrypt,
combine_decryption_shares_simple,
combine_decryption_shares_precomputed,
diff --git a/ferveo-python/test/test_serialization.py b/ferveo-python/test/test_serialization.py
index 6b564be2..ee48cd8a 100644
--- a/ferveo-python/test/test_serialization.py
+++ b/ferveo-python/test/test_serialization.py
@@ -1,4 +1,4 @@
-from ferveo_py import (
+from ferveo import (
Keypair,
Validator,
Dkg,
diff --git a/ferveo/src/bindings_python.rs b/ferveo/src/bindings_python.rs
index cf19ebc9..99538e60 100644
--- a/ferveo/src/bindings_python.rs
+++ b/ferveo/src/bindings_python.rs
@@ -193,6 +193,7 @@ macro_rules! generate_boxed_bytes_serialization {
#[pymethods]
impl $struct_name {
#[staticmethod]
+ #[pyo3(signature = (bytes))]
pub fn from_bytes(bytes: &[u8]) -> PyResult {
Ok($struct_name(
$inner_struct_name::from_bytes(bytes).map_err(|err| {