2019-11-26 16:10:20 +08:00
|
|
|
from libp2p.crypto.keys import PublicKey
|
|
|
|
|
|
|
|
from .pb import rpc_pb2
|
|
|
|
|
|
|
|
|
|
|
|
def signature_validator(pubkey: PublicKey, msg: rpc_pb2.Message) -> bool:
|
2019-10-25 02:10:45 +08:00
|
|
|
"""
|
|
|
|
Verify the message against the given public key.
|
2019-10-24 14:41:10 +08:00
|
|
|
|
2019-08-04 18:13:23 +08:00
|
|
|
:param pubkey: the public key which signs the message.
|
|
|
|
:param msg: the message signed.
|
|
|
|
"""
|
2019-11-26 16:10:20 +08:00
|
|
|
try:
|
|
|
|
pubkey.verify(msg.SerializeToString(), msg.signature)
|
|
|
|
except Exception:
|
|
|
|
return False
|
2019-08-04 18:13:23 +08:00
|
|
|
return True
|