Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Python typings #139

Merged
merged 9 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 0 additions & 104 deletions .github/workflows/maturin.yml

This file was deleted.

8 changes: 6 additions & 2 deletions .github/workflows/workspace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
Expand Down
11 changes: 11 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]

[dev-packages]

[requires]
python_version = "3.10"
8 changes: 0 additions & 8 deletions ferveo-python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ publish = false

[lib]
crate-type = ["cdylib"]
name = "ferveo_py"

[features]
extension-module = ["pyo3/extension-module"]
Expand All @@ -18,12 +17,5 @@ default = ["extension-module"]
ferveo = { package = "ferveo-pre-release", path = "../ferveo", features = ["bindings-python"] }
pyo3 = "0.18.2"

# We avoid declaring "pyo3/extension-module" in `dependencies` since it causes compile-time issues:
# https://github.com/PyO3/pyo3/issues/340
# Instead, we expose it in certain cases:
# https://github.com/PyO3/maturin/issues/325
KPrasch marked this conversation as resolved.
Show resolved Hide resolved
[tool.maturin]
features = ["pyo3/extension-module"]

[build-dependencies]
pyo3-build-config = "*"
11 changes: 11 additions & 0 deletions ferveo-python/Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]

[dev-packages]

[requires]
python_version = "3.10"
7 changes: 0 additions & 7 deletions ferveo-python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,3 @@
## Build

You will need to have `setuptools-rust` installed. Then, for development, you can just do `pip install -e .` as usual.

## Publish

```bash
maturin build --release
maturin publish
```
2 changes: 1 addition & 1 deletion ferveo-python/examples/exception.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ferveo_py import (
from ferveo import (
Keypair,
Validator,
Dkg,
Expand Down
2 changes: 1 addition & 1 deletion ferveo-python/examples/server_api_precomputed.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ferveo_py import (
from ferveo import (
encrypt,
combine_decryption_shares_precomputed,
decrypt_with_shared_secret,
Expand Down
2 changes: 1 addition & 1 deletion ferveo-python/examples/server_api_simple.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ferveo_py import (
from ferveo import (
encrypt,
combine_decryption_shares_simple,
decrypt_with_shared_secret,
Expand Down
2 changes: 1 addition & 1 deletion ferveo-python/ferveo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .ferveo_py import (
from ._ferveo import (
encrypt,
combine_decryption_shares_simple,
combine_decryption_shares_precomputed,
Expand Down
43 changes: 30 additions & 13 deletions ferveo-python/ferveo/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
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(secure_randomness: bytes) -> Keypair:
...

@staticmethod
def secure_randomness_size(data: bytes) -> int:
def secure_randomness_size() -> int:
...

@staticmethod
Expand All @@ -25,6 +26,7 @@ class Keypair:
...


@final
class FerveoPublicKey:
@staticmethod
def from_bytes(data: bytes) -> FerveoPublicKey:
Expand All @@ -36,10 +38,15 @@ class FerveoPublicKey:
def __hash__(self) -> int:
...

def __richcmp__(self, other: FerveoPublicKey, op: int) -> bool:
@staticmethod
def serialized_size() -> int:
...

def __eq__(self, other: object) -> bool:
...


@final
class Validator:

def __init__(self, address: str, public_key: FerveoPublicKey):
Expand All @@ -50,6 +57,7 @@ class Validator:
public_key: FerveoPublicKey


@final
class Transcript:
@staticmethod
def from_bytes(data: bytes) -> Transcript:
Expand All @@ -59,6 +67,7 @@ class Transcript:
...


@final
class DkgPublicKey:
@staticmethod
def from_bytes(data: bytes) -> DkgPublicKey:
Expand All @@ -67,7 +76,12 @@ class DkgPublicKey:
def __bytes__(self) -> bytes:
...

@staticmethod
def serialized_size() -> int:
...


@final
class ValidatorMessage:

def __init__(
Expand All @@ -81,6 +95,7 @@ class ValidatorMessage:
transcript: Transcript


@final
class Dkg:

def __init__(
Expand All @@ -102,6 +117,7 @@ class Dkg:
...


@final
class Ciphertext:
@staticmethod
def from_bytes(data: bytes) -> Ciphertext:
Expand All @@ -111,6 +127,7 @@ class Ciphertext:
...


@final
class DecryptionShareSimple:
@staticmethod
def from_bytes(data: bytes) -> DecryptionShareSimple:
Expand All @@ -120,6 +137,7 @@ class DecryptionShareSimple:
...


@final
class DecryptionSharePrecomputed:
@staticmethod
def from_bytes(data: bytes) -> DecryptionSharePrecomputed:
Expand All @@ -129,6 +147,7 @@ class DecryptionSharePrecomputed:
...


@final
class AggregatedTranscript:

def __init__(self, messages: Sequence[ValidatorMessage]):
Expand Down Expand Up @@ -163,6 +182,7 @@ class AggregatedTranscript:
...


@final
class SharedSecret:

@staticmethod
Expand All @@ -173,15 +193,16 @@ class SharedSecret:
...


@final
class FerveoVariant:
@staticmethod
def simple() -> str: ...
simple: FerveoVariant
precomputed: FerveoVariant
Copy link
Member

@derekpierre derekpierre Jul 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor nitpick I didn't pick up on earlier (and I know it's annoying), but can these be SIMPLE/PRECOMPUTED or Simple/Precomputed. The lowercase looks a little weird in the Python code 😅

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are class attributes, so I assumed they should be lowercase. I can fix this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see. Admittedly, it's a nitpick so if it is easy to fix/makes sense then great; if not, then you can ignore.

I didn't notice it until I saw it used in the 3171.


@staticmethod
def precomputed() -> str: ...
def __eq__(self, other: object) -> bool:
...


def encrypt(message: bytes, add: bytes, dkg_public_key: DkgPublicKey) -> Ciphertext:
def encrypt(message: bytes, aad: bytes, dkg_public_key: DkgPublicKey) -> Ciphertext:
...


Expand Down Expand Up @@ -267,7 +288,3 @@ class ValidatorPublicKeyMismatch(Exception):

class SerializationError(Exception):
pass


class InvalidVariant(Exception):
pass
12 changes: 1 addition & 11 deletions ferveo-python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
[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",
]
requires = ["setuptools", "wheel", "setuptools-rust"]


2 changes: 1 addition & 1 deletion ferveo-python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Loading
Loading