diff --git a/setup.cfg b/setup.cfg index a41e52f4..1d71a697 100644 --- a/setup.cfg +++ b/setup.cfg @@ -34,8 +34,6 @@ install_requires = coincurve; python_version<"3.11" coincurve>=17.0.0; python_version>="3.11" # Technically, this should be >=18.0.0 but there is a conflict with eciespy aiohttp>=3.8.3 - eciespy; python_version<"3.11" - eciespy>=0.3.13; python_version>="3.11" typing_extensions typer aleph-message~=0.4.3 @@ -83,6 +81,8 @@ testing = py-sr25519-bindings ledgereth==0.9.0 aiodns + eciespy; python_version<"3.11" + eciespy>=0.3.13; python_version>="3.11" dns = aiodns mqtt = @@ -110,6 +110,9 @@ ledger = ledgereth==0.9.0 docs = sphinxcontrib-plantuml +encryption = + eciespy; python_version<"3.11" + eciespy>=0.3.13; python_version>="3.11" [options.entry_points] # Add here console scripts like: diff --git a/src/aleph/sdk/chains/common.py b/src/aleph/sdk/chains/common.py index 3c7e634e..b73d6e41 100644 --- a/src/aleph/sdk/chains/common.py +++ b/src/aleph/sdk/chains/common.py @@ -4,7 +4,7 @@ from typing import Dict, Optional from coincurve.keys import PrivateKey -from ecies import decrypt, encrypt +from typing_extensions import deprecated from aleph.sdk.conf import settings from aleph.sdk.utils import enum_as_str @@ -100,6 +100,7 @@ def get_public_key(self) -> str: """ raise NotImplementedError + @deprecated("This method will be moved to its own module `aleph.sdk.encryption`") async def encrypt(self, content: bytes) -> bytes: """ Encrypts a message using the account's public key. @@ -108,12 +109,19 @@ async def encrypt(self, content: bytes) -> bytes: Returns: bytes: Encrypted content as bytes """ + try: + from ecies import encrypt + except ImportError: + raise ImportError( + "Install `eciespy` or `aleph-sdk-python[encryption]` to use this method" + ) if self.CURVE == "secp256k1": value: bytes = encrypt(self.get_public_key(), content) return value else: raise NotImplementedError + @deprecated("This method will be moved to its own module `aleph.sdk.encryption`") async def decrypt(self, content: bytes) -> bytes: """ Decrypts a message using the account's private key. @@ -122,6 +130,12 @@ async def decrypt(self, content: bytes) -> bytes: Returns: bytes: Decrypted content as bytes """ + try: + from ecies import decrypt + except ImportError: + raise ImportError( + "Install `eciespy` or `aleph-sdk-python[encryption]` to use this method" + ) if self.CURVE == "secp256k1": value: bytes = decrypt(self.private_key, content) return value