Skip to content

Commit

Permalink
Merge pull request #126 from piotr-roslaniec/fix-typings
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-roslaniec authored Aug 1, 2023
2 parents c7ff412 + 583f81b commit eb404fc
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 24 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/umbral-pre.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,43 @@ jobs:
- run: cargo check --all-features
- run: cargo test --release --all-features

python-test:
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- stable
python:
- "3.10"
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}

- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
override: true

- name: Install umbral_pre package
run: pip install -e .
working-directory: umbral-pre-python

- name: Run Python example
run: python example/example.py
working-directory: umbral-pre-python

- name: Install pip dependencies
run: pip install mypy

- name: Run mypy.stubtest
run: python -m mypy.stubtest umbral_pre --allowlist stubtest-allowlist.txt
working-directory: umbral-pre-python

trigger-wheels:
runs-on: ubuntu-latest
needs: test
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Added `bindings_wasm::SecretKey::equals`. ([#125])
- Update Python bindings. ([#126])

[#125]: https://github.com/nucypher/rust-umbral/pull/125
[#126]: https://github.com/nucypher/rust-umbral/pull/126


## [0.10.0] - 2023-05-29
Expand Down
13 changes: 11 additions & 2 deletions umbral-pre-python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,18 @@ This repo contains the Python bindings for the [main Rust project][umbral-pre].
You will need to have `setuptools-rust` installed. Then, for development you can just do `pip install -e .` as usual.

Building Linux wheels must be done via Docker (makefile under construction).
```bash
docker pull quay.io/pypa/manylinux2014_x86_64
docker run --rm -v `pwd`/..:/io quay.io/pypa/manylinux2014_x86_64 /io/umbral-pre-python/build-wheels.sh
```
$ docker pull quay.io/pypa/manylinux2014_x86_64
$ docker run --rm -v `pwd`/..:/io quay.io/pypa/manylinux2014_x86_64 /io/umbral-pre-python/build-wheels.sh

## Development

Update `umbral-pre-python/stubtest-allowlist.txt` with:
```bash
cd umbral-pre-python
python -m mypy.stubtest umbral_pre --generate-allowlist > stubtest-allowlist.txt

```

[pypi-image]: https://img.shields.io/pypi/v/umbral-pre
Expand Down
1 change: 1 addition & 0 deletions umbral-pre-python/stubtest-allowlist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
umbral_pre.Parameters.__init__
2 changes: 1 addition & 1 deletion umbral-pre-python/umbral_pre/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
decrypt_reencrypted,
generate_kfrags,
reencrypt,
)
)
50 changes: 29 additions & 21 deletions umbral-pre-python/umbral_pre/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Optional, Tuple, List, Sequence
from typing import Optional, Tuple, List, final, Sequence


@final
class SecretKey:

@staticmethod
Expand All @@ -18,6 +19,7 @@ class SecretKey:
...


@final
class SecretKeyFactory:

@staticmethod
Expand All @@ -28,10 +30,6 @@ class SecretKeyFactory:
def seed_size() -> int:
...

@staticmethod
def from_secure_randomness(seed: bytes) -> SecretKeyFactory:
...

def make_secret(self, label: bytes) -> bytes:
...

Expand All @@ -42,10 +40,11 @@ class SecretKeyFactory:
...

@staticmethod
def from_secure_randomness(data: bytes) -> SecretKeyFactory:
def from_secure_randomness(seed: bytes) -> SecretKeyFactory:
...


@final
class PublicKey:

@staticmethod
Expand All @@ -60,6 +59,7 @@ class PublicKey:
...


@final
class Signer:

def __init__(self, secret_key: SecretKey):
Expand All @@ -72,6 +72,7 @@ class Signer:
...


@final
class Signature:

def verify(self, verifying_pk: PublicKey, message: bytes) -> bool:
Expand All @@ -92,6 +93,7 @@ class Signature:
...


@final
class RecoverableSignature:

@staticmethod
Expand All @@ -102,6 +104,7 @@ class RecoverableSignature:
...


@final
class Capsule:

@staticmethod
Expand All @@ -123,14 +126,15 @@ def decrypt_original(delegating_sk: SecretKey, capsule: Capsule, ciphertext: byt
...


@final
class KeyFrag:

def verify(
self,
verifying_pk: PublicKey,
delegating_pk: Optional[PublicKey],
receiving_pk: Optional[PublicKey],
) -> VerifiedKeyFrag:
delegating_pk: Optional[PublicKey] = None,
receiving_pk: Optional[PublicKey] = None,
) -> VerifiedKeyFrag:
...

def skip_verification(self) -> VerifiedKeyFrag:
Expand All @@ -144,6 +148,7 @@ class KeyFrag:
...


@final
class VerifiedKeyFrag:

def __bytes__(self) -> bytes:
Expand All @@ -161,10 +166,11 @@ def generate_kfrags(
shares: int,
sign_delegating_key: bool,
sign_receiving_key: bool,
) -> List[VerifiedKeyFrag]:
) -> List[VerifiedKeyFrag]:
...


@final
class CapsuleFrag:

def verify(
Expand All @@ -173,7 +179,7 @@ class CapsuleFrag:
verifying_pk: PublicKey,
delegating_pk: PublicKey,
receiving_pk: PublicKey,
) -> VerifiedCapsuleFrag:
) -> VerifiedCapsuleFrag:
...

def skip_verification(self) -> VerifiedCapsuleFrag:
Expand All @@ -190,6 +196,7 @@ class CapsuleFrag:
...


@final
class VerifiedCapsuleFrag:

def __bytes__(self) -> bytes:
Expand All @@ -202,26 +209,26 @@ class VerifiedCapsuleFrag:
...


def reencrypt(capsule: Capsule, kfrag: VerifiedKeyFrag) -> VerifiedCapsuleFrag:
...


def decrypt_reencrypted(
receiving_sk: SecretKey,
delegating_pk: PublicKey,
capsule: Capsule,
cfrags: Sequence[VerifiedCapsuleFrag],
verified_cfrags: Sequence[VerifiedCapsuleFrag],
ciphertext: bytes,
) -> Optional[bytes]:
) -> Optional[bytes]:
...


class CurvePoint:
def reencrypt(capsule: Capsule, kfrag: VerifiedKeyFrag) -> VerifiedCapsuleFrag:
...

def coordinates(self) -> Tuple[bytes, bytes]:
...

@final
class CurvePoint:
coordinates: Optional[Tuple[bytes, bytes]]


@final
class Parameters:

def __init__(self) -> None:
Expand All @@ -230,6 +237,7 @@ class Parameters:
u: CurvePoint


@final
class ReencryptionEvidence:

def __init__(
Expand All @@ -239,7 +247,7 @@ class ReencryptionEvidence:
verifying_pk: PublicKey,
delegating_pk: PublicKey,
receiving_pk: PublicKey,
):
):
...

def __bytes__(self) -> bytes:
Expand Down
2 changes: 2 additions & 0 deletions umbral-pre/src/bindings_python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ pub struct KeyFrag {

#[pymethods]
impl KeyFrag {
// Fixing signature expansion to satisfy mypy.stubtest
#[pyo3(text_signature = "(self, verifying_pk, delegating_pk=None, receiving_pk=None)")]
pub fn verify(
&self,
verifying_pk: &PublicKey,
Expand Down

0 comments on commit eb404fc

Please sign in to comment.