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
7 changes: 5 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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:
Expand Down
16 changes: 15 additions & 1 deletion src/aleph/sdk/chains/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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
Expand Down