Skip to content

[WIP]feat: code upgrades/streamlining from python 3.10 => 3.11 #1211

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ packages =
package_dir =
=src

python_requires = >=3.10
python_requires = >=3.11
install_requires =
pycryptodome>=3,<4
coincurve>=20,<21
Expand Down
13 changes: 6 additions & 7 deletions src/ethereum/crypto/elliptic_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
^^^^^^^^^^^^^^^
"""

from typing import Generic, Type, TypeVar
from typing import Generic, Type, TypeVar, Self

import coincurve
from ethereum_types.bytes import Bytes
Expand All @@ -17,7 +17,6 @@
)

F = TypeVar("F", bound=Field)
T = TypeVar("T", bound="EllipticCurve")


def secp256k1_recover(r: U256, s: U256, v: U256, msg_hash: Hash32) -> Bytes:
Expand Down Expand Up @@ -69,7 +68,7 @@ class EllipticCurve(Generic[F]):
x: F
y: F

def __new__(cls: Type[T], x: F, y: F) -> T:
def __new__(cls, x: F, y: F) -> Self:
"""
Make new point on the curve. The point is not checked to see if it is
on the curve.
Expand Down Expand Up @@ -104,7 +103,7 @@ def __str__(self) -> str:
return str((self.x, self.y))

@classmethod
def point_at_infinity(cls: Type[T]) -> T:
def point_at_infinity(cls) -> Self:
"""
Return the point at infinity. This is the identity element of the group
operation.
Expand All @@ -114,7 +113,7 @@ def point_at_infinity(cls: Type[T]) -> T:
"""
return cls.__new__(cls, cls.FIELD.zero(), cls.FIELD.zero())

def double(self: T) -> T:
def double(self) -> Self:
"""
Add a point to itself.
"""
Expand All @@ -126,7 +125,7 @@ def double(self: T) -> T:
new_y = lam * (x - new_x) - y
return self.__new__(type(self), new_x, new_y)

def __add__(self: T, other: T) -> T:
def __add__(self, other: Self) -> Self:
"""
Add two points together.
"""
Expand All @@ -146,7 +145,7 @@ def __add__(self: T, other: T) -> T:
y = lam * (self_x - x) - self_y
return self.__new__(type(self), x, y)

def mul_by(self: T, n: int) -> T:
def mul_by(self, n: int) -> Self:
"""
Multiply `self` by `n` using the double and add algorithm.
"""
Expand Down
Loading