Implement Pubsub signature validator

This commit is contained in:
NIC619 2019-11-26 16:10:20 +08:00
parent 683710573e
commit f3c9972159
No known key found for this signature in database
GPG Key ID: 570C35F5C2D51B17

View File

@ -1,10 +1,17 @@
# FIXME: Replace the type of `pubkey` with a custom type `Pubkey`
def signature_validator(pubkey: bytes, msg: bytes) -> bool:
from libp2p.crypto.keys import PublicKey
from .pb import rpc_pb2
def signature_validator(pubkey: PublicKey, msg: rpc_pb2.Message) -> bool:
"""
Verify the message against the given public key.
:param pubkey: the public key which signs the message.
:param msg: the message signed.
"""
# TODO: Implement the signature validation
try:
pubkey.verify(msg.SerializeToString(), msg.signature)
except Exception:
return False
return True