diff --git a/libp2p/crypto/ed25519.py b/libp2p/crypto/ed25519.py index 61c4631..cde2641 100644 --- a/libp2p/crypto/ed25519.py +++ b/libp2p/crypto/ed25519.py @@ -47,6 +47,11 @@ class Ed25519PrivateKey(PrivateKey): def to_bytes(self) -> bytes: return bytes(self.impl) + @classmethod + def from_bytes(cls, data: bytes) -> "Ed25519PrivateKey": + impl = PrivateKeyImpl(data) + return cls(impl) + def get_type(self) -> KeyType: return KeyType.Ed25519 diff --git a/libp2p/crypto/serialization.py b/libp2p/crypto/serialization.py index 401f936..d453bfe 100644 --- a/libp2p/crypto/serialization.py +++ b/libp2p/crypto/serialization.py @@ -1,4 +1,4 @@ -from libp2p.crypto.ed25519 import Ed25519PublicKey +from libp2p.crypto.ed25519 import Ed25519PrivateKey, Ed25519PublicKey from libp2p.crypto.exceptions import MissingDeserializerError from libp2p.crypto.keys import KeyType, PrivateKey, PublicKey from libp2p.crypto.rsa import RSAPublicKey @@ -11,7 +11,8 @@ key_type_to_public_key_deserializer = { } key_type_to_private_key_deserializer = { - KeyType.Secp256k1.value: Secp256k1PrivateKey.from_bytes + KeyType.Secp256k1.value: Secp256k1PrivateKey.from_bytes, + KeyType.Ed25519.value: Ed25519PrivateKey.from_bytes, }