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 bindings #72

Merged
merged 11 commits into from
Aug 1, 2023
Merged

Conversation

piotr-roslaniec
Copy link
Contributor

@piotr-roslaniec piotr-roslaniec commented Jul 10, 2023

Type of PR:

  • Bugfix

Required reviews:

  • 2

What this does:

  • Fixes some Python typings not matching their runtime definition
  • Adds mypy.stubtest check to CI

Issues fixed/closed:

Why it's needed:

  • Implements downstream changes of aforementioned issues

Notes for reviewers:

@codecov-commenter
Copy link

codecov-commenter commented Jul 10, 2023

Codecov Report

Merging #72 (a2a860d) into development (0abc213) will increase coverage by 0.15%.
Report is 1 commits behind head on development.
The diff coverage is 87.09%.

@@               Coverage Diff               @@
##           development      #72      +/-   ##
===============================================
+ Coverage        21.07%   21.22%   +0.15%     
===============================================
  Files               17       16       -1     
  Lines             3194     3176      -18     
===============================================
+ Hits               673      674       +1     
+ Misses            2521     2502      -19     
Files Changed Coverage Δ
nucypher-core-python/src/lib.rs 0.00% <0.00%> (-0.11%) ⬇️
nucypher-core-wasm/src/lib.rs 0.00% <0.00%> (-0.13%) ⬇️
nucypher-core/src/dkg.rs 89.65% <100.00%> (+0.08%) ⬆️

... and 1 file with indirect coverage changes

@piotr-roslaniec piotr-roslaniec marked this pull request as ready for review July 11, 2023 09:03
ThresholdEncryptionError = _ferveo.ThresholdEncryptionError
InvalidShareNumberParameter = _ferveo.InvalidShareNumberParameter
Copy link
Member

Choose a reason for hiding this comment

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

Excellent, looking forward to using DKG size 3 of 5 on testnets!

class Keypair:
@staticmethod
def random() -> Keypair:
...

@staticmethod
def from_secure_randomness(data: bytes) -> Keypair:
def from_secure_randomness(bytes: bytes) -> Keypair:
Copy link
Member

Choose a reason for hiding this comment

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

the name shadowing of the bytes function here strikes me as a bit unusual, even in the context of a stub. I'd suggest sticking with some variant of data (payload, secure_bytes) or at minimum prepend with an underscore (_bytes.)

Do the parameter stubs need to be identical to the actual binding definition? If so, then this will lead to the bytes function also being overloaded within the scope of this method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

✔️

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I got weirded out a little myself, but wasn't sure if I should comment on it :)

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

@staticmethod
def from_secure_randomness(data: bytes) -> SecretKeyFactory:
def from_secure_randomness(seed: bytes) -> SecretKeyFactory:
Copy link
Member

@KPrasch KPrasch Jul 11, 2023

Choose a reason for hiding this comment

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

I see you decided to use a different name here compared to the ferveo key above - seed is a better name for this param considering it's intended usage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Going to use secure_randomness in both

Copy link
Member

@KPrasch KPrasch left a comment

Choose a reason for hiding this comment

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

Looks mostly good, Just a few comments about name shadowing.

@piotr-roslaniec piotr-roslaniec changed the base branch from ferveo-alpha-11 to development July 11, 2023 10:20
@piotr-roslaniec piotr-roslaniec force-pushed the fix-typings branch 3 times, most recently from 290263a to bb1c65e Compare July 13, 2023 08:43
@piotr-roslaniec piotr-roslaniec changed the title Update Python bindings Update bindings Jul 13, 2023
policy_encrypting_key: PublicKey,
plaintext: bytes,
conditions: Optional[Conditions]
self,
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.

Is this spacing correct / necessary (eg. linter)? It really increases the diff.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was my IDE's formatter, sorry about that.

Now that I think about it I should adopt formatting style & utilities from nucypher into Python bindings everywhere.

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.

All good - no need to be sorry. I guess we do need to think about linting in these other repos.

Copy link
Member

@manumonti manumonti left a comment

Choose a reason for hiding this comment

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

Not an expert on Rust, but it looks good! 👍

Just a few of comments.

Comment on lines 22 to 23
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 = "cea467e0bd48a096f70dd1c7ca24a7e4bd88b3d4" }
Copy link
Member

Choose a reason for hiding this comment

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

Should we add a TODO: here to note that these are not final versions? (or at least I guess so)

Copy link
Contributor Author

@piotr-roslaniec piotr-roslaniec Jul 13, 2023

Choose a reason for hiding this comment

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

This PR is not getting merged until those downstream dependencies get released. In the future, I will document this in a PR description or using a TODO.

...


def encrypt(message: bytes, aad: bytes, dkg_public_key: DkgPublicKey) -> Ciphertext:
Copy link
Member

Choose a reason for hiding this comment

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

Just to confirm. Is this aad variable correctly spelled? what does it stand for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

it makes sense. Thanks

Comment on lines 280 to 283
type SessionSecretFactorySeedSize = U32;
// the size of the seed material for key derivation
type SessionSecretFactoryDerivedKeySize = U32;
// the size of the derived key
Copy link
Member

Choose a reason for hiding this comment

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

IMHO the comments should be placed above the line and not under the line they refer. (this seems like a formatting tool thing)

Suggested change
type SessionSecretFactorySeedSize = U32;
// the size of the seed material for key derivation
type SessionSecretFactoryDerivedKeySize = U32;
// the size of the derived key
// the size of the seed material for key derivation
type SessionSecretFactorySeedSize = U32;
// the size of the derived key
type SessionSecretFactoryDerivedKeySize = U32;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cargo fmt is messing these up constantly for me, I may need to edit formatting rules.

@@ -10,8 +10,8 @@ readme = "README.md"
categories = ["cryptography", "no-std"]

[dependencies]
umbral-pre = { version = "0.10.0", features = ["serde"] }
ferveo = { package = "ferveo-pre-release", version = "0.2.0" }
umbral-pre = { version = "0.10.0", features = ["serde"], git = "https://github.com/piotr-roslaniec/rust-umbral.git", rev = "fd2e16f9304b9dab85c9a8947a61d962ff136131" }
Copy link
Member

Choose a reason for hiding this comment

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

Should we add a TODO: here to note that these are not final versions? (or at least I guess so)

Copy link
Member

@manumonti manumonti left a comment

Choose a reason for hiding this comment

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

LGTM! ✌️

@piotr-roslaniec piotr-roslaniec merged commit 2e8bb1c into nucypher:development Aug 1, 2023
8 of 9 checks passed
@piotr-roslaniec piotr-roslaniec deleted the fix-typings branch August 1, 2023 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants