From ee290b2ac2f04280c75655ab42d0570b825d1026 Mon Sep 17 00:00:00 2001 From: NIC619 Date: Fri, 2 Aug 2019 16:48:32 +0800 Subject: [PATCH] Fix missing asterisk --- libp2p/peer/id.py | 32 -------------------------------- libp2p/transport/tcp/tcp.py | 4 ++-- 2 files changed, 2 insertions(+), 34 deletions(-) diff --git a/libp2p/peer/id.py b/libp2p/peer/id.py index 9ad8821..48b4892 100644 --- a/libp2p/peer/id.py +++ b/libp2p/peer/id.py @@ -82,38 +82,6 @@ class ID: return cls.from_pubkey(key.publickey()) -def id_b58_encode(peer_id: ID) -> str: - """ - return a b58-encoded string - """ - # pylint: disable=protected-access - return base58.b58encode(peer_id.to_bytes()).decode() - - -def id_b58_decode(b58_encoded_peer_id_str: str) -> ID: - """ - return a base58-decoded peer ID - """ - return ID(base58.b58decode(b58_encoded_peer_id_str)) - - -def id_from_public_key(key: RsaKey) -> ID: - # export into binary format - key_bin = key.exportKey("DER") - - algo: int = multihash.Func.sha2_256 - # TODO: seems identity is not yet supported in pymultihash - # if len(b) <= MAX_INLINE_KEY_LENGTH: - # algo multihash.func.identity - - mh_digest: multihash.Multihash = multihash.digest(key_bin, algo) - return ID(mh_digest.encode()) - - -def id_from_private_key(key: RsaKey) -> ID: - return id_from_public_key(key.publickey()) - - def digest(data: Union[str, bytes]) -> bytes: if isinstance(data, str): data = data.encode("utf8") diff --git a/libp2p/transport/tcp/tcp.py b/libp2p/transport/tcp/tcp.py index 8f88430..e497c73 100644 --- a/libp2p/transport/tcp/tcp.py +++ b/libp2p/transport/tcp/tcp.py @@ -3,7 +3,7 @@ import asyncio import multiaddr from libp2p.network.connection.raw_connection import RawConnection -from libp2p.peer.id import id_b58_encode +from libp2p.peer.id import ID from ..listener_interface import IListener from ..transport_interface import ITransport @@ -74,7 +74,7 @@ class TCP(ITransport): reader, writer = await asyncio.open_connection(host, port) # First: send our peer ID so receiver knows it - writer.write(id_b58_encode(self_id).encode()) + writer.write(self_id.to_base58().encode()) await writer.drain() # Await ack for peer id