diff --git a/.github/workflows/nucypher-core.yml b/.github/workflows/nucypher-core.yml index d27b2931..1c802a03 100644 --- a/.github/workflows/nucypher-core.yml +++ b/.github/workflows/nucypher-core.yml @@ -125,7 +125,7 @@ jobs: run: pip install mypy - name: Run mypy.stubtest - run: python -m mypy.stubtest nucypher_core + run: python -m mypy.stubtest nucypher_core --allowlist stubtest-allowlist.txt working-directory: nucypher-core-python trigger-wheels: diff --git a/Cargo.lock b/Cargo.lock index 1ac07297..c730d786 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -518,7 +518,7 @@ dependencies = [ [[package]] name = "ferveo-common-pre-release" version = "0.1.0" -source = "git+https://github.com/nucypher/ferveo.git#434fd5d07b54e72d120e9aa06cbc3e47848e6bcf" +source = "git+https://github.com/nucypher/ferveo.git?rev=c3b749732cc2d560240f7a1043c18d10138e30e9#c3b749732cc2d560240f7a1043c18d10138e30e9" dependencies = [ "ark-ec", "ark-serialize", @@ -533,7 +533,7 @@ dependencies = [ [[package]] name = "ferveo-pre-release" version = "0.2.0" -source = "git+https://github.com/nucypher/ferveo.git#434fd5d07b54e72d120e9aa06cbc3e47848e6bcf" +source = "git+https://github.com/nucypher/ferveo.git?rev=c3b749732cc2d560240f7a1043c18d10138e30e9#c3b749732cc2d560240f7a1043c18d10138e30e9" dependencies = [ "ark-bls12-381", "ark-ec", @@ -636,7 +636,7 @@ dependencies = [ [[package]] name = "group-threshold-cryptography-pre-release" version = "0.1.0" -source = "git+https://github.com/nucypher/ferveo.git#434fd5d07b54e72d120e9aa06cbc3e47848e6bcf" +source = "git+https://github.com/nucypher/ferveo.git?rev=c3b749732cc2d560240f7a1043c18d10138e30e9#c3b749732cc2d560240f7a1043c18d10138e30e9" dependencies = [ "ark-bls12-381", "ark-ec", @@ -1392,7 +1392,7 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "subproductdomain-pre-release" version = "0.1.0" -source = "git+https://github.com/nucypher/ferveo.git#434fd5d07b54e72d120e9aa06cbc3e47848e6bcf" +source = "git+https://github.com/nucypher/ferveo.git?rev=c3b749732cc2d560240f7a1043c18d10138e30e9#c3b749732cc2d560240f7a1043c18d10138e30e9" dependencies = [ "anyhow", "ark-ec", @@ -1491,7 +1491,7 @@ checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" [[package]] name = "umbral-pre" version = "0.10.0" -source = "git+https://github.com/piotr-roslaniec/rust-umbral.git#c7ff41296e26ae0696f84f4a62fd26d619479c52" +source = "git+https://github.com/piotr-roslaniec/rust-umbral.git?rev=fd2e16f9304b9dab85c9a8947a61d962ff136131#fd2e16f9304b9dab85c9a8947a61d962ff136131" dependencies = [ "base64 0.21.2", "chacha20poly1305", diff --git a/nucypher-core-python/Cargo.toml b/nucypher-core-python/Cargo.toml index 7aae50fd..0130c80f 100644 --- a/nucypher-core-python/Cargo.toml +++ b/nucypher-core-python/Cargo.toml @@ -10,8 +10,8 @@ crate-type = ["cdylib"] [dependencies] pyo3 = "0.18" nucypher-core = { path = "../nucypher-core" } -umbral-pre = { version = "0.10.0", features = ["bindings-python"], git = "https://github.com/piotr-roslaniec/rust-umbral.git", ref = "4b28a85c494e4e2640abb131460da0680a74134d" } -ferveo = { package = "ferveo-pre-release", features = ["bindings-python"], git = "https://github.com/nucypher/ferveo.git", ref = "fbb97be59d991a263233a0b876da982143b2cbf2" } +umbral-pre = { version = "0.10.0", features = ["bindings-python"], git = "https://github.com/piotr-roslaniec/rust-umbral.git", rev = "fd2e16f9304b9dab85c9a8947a61d962ff136131" } +ferveo = { package = "ferveo-pre-release", features = ["bindings-python"], git = "https://github.com/nucypher/ferveo.git", rev = "c3b749732cc2d560240f7a1043c18d10138e30e9" } derive_more = { version = "0.99", default-features = false, features = ["from", "as_ref"] } [build-dependencies] diff --git a/nucypher-core-python/README.md b/nucypher-core-python/README.md index 90db8b68..1163f9c1 100644 --- a/nucypher-core-python/README.md +++ b/nucypher-core-python/README.md @@ -9,6 +9,13 @@ This repo contains the Python bindings for the [main Rust project][nucypher-core You will need to have `setuptools-rust` installed. Then, for development you can just do `pip install -e .` as usual. +## Development + +Update `nucypher-core-python/stubtest-allowlist.txt` with: +```bash +cd umbral-pre-python +python -m mypy.stubtest nucypher_core --generate-allowlist > stubtest-allowlist.txt +``` [pypi-image]: https://img.shields.io/pypi/v/nucypher-core [pypi-link]: https://pypi.org/project/nucypher-core/ diff --git a/nucypher-core-python/nucypher_core/__init__.pyi b/nucypher-core-python/nucypher_core/__init__.pyi index 677d609f..96093475 100644 --- a/nucypher-core-python/nucypher_core/__init__.pyi +++ b/nucypher-core-python/nucypher_core/__init__.pyi @@ -12,7 +12,8 @@ from .umbral import ( from .ferveo import ( FerveoPublicKey, - Ciphertext + Ciphertext, + FerveoVariant ) @@ -431,7 +432,7 @@ class MetadataResponse: @final class ThresholdDecryptionRequest: - def __init__(self, ritual_id: int, variant: int, ciphertext: Ciphertext, conditions: Optional[Conditions], + def __init__(self, ritual_id: int, variant: FerveoVariant, ciphertext: Ciphertext, conditions: Optional[Conditions], context: Optional[Context]): ... @@ -441,7 +442,7 @@ class ThresholdDecryptionRequest: context: Optional[Context] - variant: int + variant: FerveoVariant ciphertext: Ciphertext diff --git a/nucypher-core-python/nucypher_core/ferveo.pyi b/nucypher-core-python/nucypher_core/ferveo.pyi index 9fc82342..7e45d878 100644 --- a/nucypher-core-python/nucypher_core/ferveo.pyi +++ b/nucypher-core-python/nucypher_core/ferveo.pyi @@ -1,5 +1,6 @@ from typing import Sequence, final + @final class Keypair: @staticmethod @@ -24,6 +25,7 @@ class Keypair: def public_key(self) -> FerveoPublicKey: ... + @final class FerveoPublicKey: @staticmethod @@ -40,6 +42,7 @@ class FerveoPublicKey: def serialized_size() -> int: ... + @final class Validator: @@ -50,6 +53,7 @@ class Validator: public_key: FerveoPublicKey + @final class Transcript: @staticmethod @@ -59,6 +63,7 @@ class Transcript: def __bytes__(self) -> bytes: ... + @final class DkgPublicKey: @staticmethod @@ -72,6 +77,7 @@ class DkgPublicKey: def serialized_size() -> int: ... + @final class ValidatorMessage: @@ -85,6 +91,7 @@ class ValidatorMessage: validator: Validator transcript: Transcript + @final class Dkg: @@ -106,6 +113,7 @@ class Dkg: def aggregate_transcripts(self, messages: Sequence[ValidatorMessage]) -> AggregatedTranscript: ... + @final class Ciphertext: @staticmethod @@ -115,6 +123,7 @@ class Ciphertext: def __bytes__(self) -> bytes: ... + @final class DecryptionShareSimple: @staticmethod @@ -123,6 +132,8 @@ class DecryptionShareSimple: def __bytes__(self) -> bytes: ... + + @final class DecryptionSharePrecomputed: @staticmethod @@ -132,6 +143,7 @@ class DecryptionSharePrecomputed: def __bytes__(self) -> bytes: ... + @final class AggregatedTranscript: @@ -166,6 +178,7 @@ class AggregatedTranscript: def __bytes__(self) -> bytes: ... + @final class SharedSecret: @@ -179,8 +192,11 @@ class SharedSecret: @final class FerveoVariant: - simple: str - precomputed: str + simple: FerveoVariant + precomputed: FerveoVariant + + def __eq__(self, other: object) -> bool: + ... def encrypt(message: bytes, aad: bytes, dkg_public_key: DkgPublicKey) -> Ciphertext: @@ -188,13 +204,13 @@ def encrypt(message: bytes, aad: bytes, dkg_public_key: DkgPublicKey) -> Ciphert def combine_decryption_shares_simple( - shares: Sequence[DecryptionShareSimple], + decryption_shares: Sequence[DecryptionShareSimple], ) -> bytes: ... def combine_decryption_shares_precomputed( - shares: Sequence[DecryptionSharePrecomputed], + decryption_shares: Sequence[DecryptionSharePrecomputed], ) -> SharedSecret: ... diff --git a/nucypher-core-python/nucypher_core/umbral.pyi b/nucypher-core-python/nucypher_core/umbral.pyi index 0733cb74..c83e56a4 100644 --- a/nucypher-core-python/nucypher_core/umbral.pyi +++ b/nucypher-core-python/nucypher_core/umbral.pyi @@ -1,4 +1,4 @@ -from typing import Optional, Tuple, List, final +from typing import Optional, Tuple, List, final, Sequence @final @@ -124,8 +124,8 @@ class KeyFrag: def verify( self, verifying_pk: PublicKey, - delegating_pk: Optional[PublicKey] = ..., - receiving_pk: Optional[PublicKey] = ..., + delegating_pk: Optional[PublicKey] = None, + receiving_pk: Optional[PublicKey] = None, ) -> VerifiedKeyFrag: ... @@ -207,13 +207,13 @@ def reencrypt(capsule: Capsule, kfrag: VerifiedKeyFrag) -> VerifiedCapsuleFrag: @final class CurvePoint: - coordinates: Tuple[bytes, bytes] + coordinates: Optional[Tuple[bytes, bytes]] @final class Parameters: - def __init__(self, *args) -> None: + def __init__(self) -> None: ... u: CurvePoint diff --git a/nucypher-core-python/src/lib.rs b/nucypher-core-python/src/lib.rs index 42d4aaba..7ecda0d7 100644 --- a/nucypher-core-python/src/lib.rs +++ b/nucypher-core-python/src/lib.rs @@ -749,7 +749,7 @@ impl ThresholdDecryptionRequest { #[new] pub fn new( ritual_id: u32, - variant: &str, + variant: FerveoVariant, ciphertext: &Ciphertext, conditions: Option<&Conditions>, context: Option<&Context>, @@ -762,7 +762,7 @@ impl ThresholdDecryptionRequest { .map(|conditions| conditions.backend.clone()) .as_ref(), context.map(|context| context.backend.clone()).as_ref(), - variant, + variant.into(), ), }) } diff --git a/nucypher-core-python/stubtest-allowlist.txt b/nucypher-core-python/stubtest-allowlist.txt new file mode 100644 index 00000000..e7fbe133 --- /dev/null +++ b/nucypher-core-python/stubtest-allowlist.txt @@ -0,0 +1 @@ +nucypher_core.umbral.Parameters.__init__ diff --git a/nucypher-core-wasm/Cargo.toml b/nucypher-core-wasm/Cargo.toml index 70de7317..efddd879 100644 --- a/nucypher-core-wasm/Cargo.toml +++ b/nucypher-core-wasm/Cargo.toml @@ -19,8 +19,8 @@ crate-type = ["cdylib", "rlib"] default = ["console_error_panic_hook"] [dependencies] -umbral-pre = { version = "0.10.0", features = ["bindings-wasm"], git = "https://github.com/piotr-roslaniec/rust-umbral.git", ref = "4b28a85c494e4e2640abb131460da0680a74134d" } -ferveo = { package = "ferveo-pre-release", features = ["bindings-wasm"], git = "https://github.com/nucypher/ferveo.git", ref = "fbb97be59d991a263233a0b876da982143b2cbf2" } +umbral-pre = { version = "0.10.0", features = ["bindings-wasm"], git = "https://github.com/piotr-roslaniec/rust-umbral.git", rev = "fd2e16f9304b9dab85c9a8947a61d962ff136131" } +ferveo = { package = "ferveo-pre-release", features = ["bindings-wasm"], git = "https://github.com/nucypher/ferveo.git", rev = "c3b749732cc2d560240f7a1043c18d10138e30e9" } nucypher-core = { path = "../nucypher-core" } wasm-bindgen = "0.2.86" js-sys = "0.3.63" diff --git a/nucypher-core/Cargo.toml b/nucypher-core/Cargo.toml index dd08e8cd..53a606cf 100644 --- a/nucypher-core/Cargo.toml +++ b/nucypher-core/Cargo.toml @@ -10,8 +10,8 @@ readme = "README.md" categories = ["cryptography", "no-std"] [dependencies] -umbral-pre = { version = "0.10.0", features = ["serde"], git = "https://github.com/piotr-roslaniec/rust-umbral.git", ref = "4b28a85c494e4e2640abb131460da0680a74134d" } -ferveo = { package = "ferveo-pre-release", git = "https://github.com/nucypher/ferveo.git", ref = "fbb97be59d991a263233a0b876da982143b2cbf2" } +umbral-pre = { version = "0.10.0", features = ["serde"], git = "https://github.com/piotr-roslaniec/rust-umbral.git", rev = "fd2e16f9304b9dab85c9a8947a61d962ff136131" } +ferveo = { package = "ferveo-pre-release", git = "https://github.com/nucypher/ferveo.git", rev = "c3b749732cc2d560240f7a1043c18d10138e30e9" } serde = { version = "1", default-features = false, features = ["derive"] } generic-array = { version = "0.14", features = ["zeroize"] } sha3 = "0.10"