Skip to content
Merged
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 .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:

- run: ./scripts/ci.sh

- uses: codecov/codecov-action@v5
- uses: codecov/codecov-action@v7
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.13'
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .ruff.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
line-length = 88

[lint]
ignore = ["E501", "W605", "E203"]
ignore = ["E501", "W605", "E203", "FA100", "UP045", "PLR0124"]

[lint.mccabe]
max-complexity = 10
2 changes: 1 addition & 1 deletion ecies/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from .keys import PrivateKey, PublicKey
from .utils import sym_decrypt, sym_encrypt

__all__ = ["encrypt", "decrypt", "ECIES_CONFIG"]
__all__ = ["ECIES_CONFIG", "decrypt", "encrypt"]


def encrypt(
Expand Down
4 changes: 2 additions & 2 deletions ecies/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ def __generate(curve: EllipticCurve):
eth_pk_bytes = pk_bytes[1:]
sk, pk = f"0x{k.to_hex()}", f"0x{eth_pk_bytes.hex()}"
address = to_eth_address(eth_pk_bytes)
print("Private: {}\nPublic: {}\nAddress: {}".format(sk, pk, address))
print(f"Private: {sk}\nPublic: {pk}\nAddress: {address}")
elif curve in ("x25519", "ed25519"):
sk, pk = f"0x{k.to_hex()}", f"0x{pk_bytes.hex()}"
print("Private: {}\nPublic: {}".format(sk, pk))
print(f"Private: {sk}\nPublic: {pk}")
else:
raise NotImplementedError

Expand Down
6 changes: 2 additions & 4 deletions ecies/keys/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ def is_valid_secret(curve: EllipticCurve, secret: bytes) -> bool:
return False
if curve == "secp256k1":
return 0 < bytes_to_int(secret) < GROUP_ORDER_INT
elif curve == "x25519":
return True
elif curve == "ed25519":
elif curve == "x25519" or curve == "ed25519":
return True
else:
raise NotImplementedError
Expand Down Expand Up @@ -54,7 +52,7 @@ def get_shared_point(
return PublicKey(pk).multiply(sk).format(compressed)
elif curve == "x25519":
return key_agreement(
kdf=lambda x: x,
kdf=bytes,
static_priv=import_x25519_private_key(sk),
eph_pub=import_x25519_public_key(pk),
)
Expand Down
21 changes: 9 additions & 12 deletions ecies/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@
from .symmetric import sym_decrypt, sym_encrypt

__all__ = [
"sym_encrypt",
"sym_decrypt",
"generate_key",
"hex2sk",
"hex2pk",
"encapsulate",
"decapsulate",
# eth
"generate_eth_key",
"to_eth_address",
# hex
"decode_hex",
# hash
"sha256",
"derive_key",
"encapsulate",
"generate_eth_key",
"generate_key",
"hex2pk",
"hex2sk",
"sha256",
"sym_decrypt",
"sym_encrypt",
"to_eth_address",
]
2 changes: 1 addition & 1 deletion ecies/utils/eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def generate_eth_key():
An ethereum flavored secp256k1 key

"""
from eth_keys import keys # type:ignore
from eth_keys import keys # pyright: ignore[reportPrivateImportUsage]

return keys.PrivateKey(get_valid_secret())

Expand Down
2 changes: 1 addition & 1 deletion ecies/utils/hex.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ def decode_hex(s: str) -> bytes:

# private below
def remove_0x(s: str) -> str:
if s.startswith("0x") or s.startswith("0X"):
if s.startswith(("0x", "0X")):
return s[2:]
return s
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ dev = [
"ipython>=9.7.0,<10; python_version >= '3.11'",
"pytest>=8.4.2,<9",
"pytest-cov>=6.3.0,<7",
"ruff>=0.14.5,<0.15",
"ty>=0.0.1a27,<0.0.2",
"ruff>=0.16.5",
"ty>=0.0.75",
]

[build-system]
Expand Down
1 change: 0 additions & 1 deletion tests/crypt/helper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from contextlib import contextmanager


from ecies import ECIES_CONFIG
from ecies.config import EllipticCurve

Expand Down
2 changes: 1 addition & 1 deletion tests/keys/test_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


def test_group_order():
sk1 = PrivateKey("secp256k1", int(1).to_bytes(32, "big"))
sk1 = PrivateKey("secp256k1", (1).to_bytes(32, "big"))
sk2 = PrivateKey("secp256k1", (GROUP_ORDER_INT - 1).to_bytes(32, "big"))
assert sk1.multiply(sk2.public_key) == sk2.public_key.to_bytes()

Expand Down
6 changes: 4 additions & 2 deletions tests/keys/test_known.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ def test_multiply(curve: EllipticCurve):
else:
raise NotImplementedError

assert PrivateKey.from_hex(curve, sk).multiply(
shared_point = PrivateKey.from_hex(curve, sk).multiply(
PublicKey.from_hex(curve, peer_pk), compressed=True
) == bytes.fromhex(shared)
)
assert isinstance(shared_point, bytes)
assert shared_point == bytes.fromhex(shared)


@pytest.mark.parametrize("curve", ["secp256k1", "x25519", "ed25519"])
Expand Down
81 changes: 40 additions & 41 deletions uv.lock

Large diffs are not rendered by default.

Loading