mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-12 16:10:57 +00:00
Implement Pubsub signature validator
This commit is contained in:
@ -1,10 +1,17 @@
|
|||||||
# FIXME: Replace the type of `pubkey` with a custom type `Pubkey`
|
from libp2p.crypto.keys import PublicKey
|
||||||
def signature_validator(pubkey: bytes, msg: bytes) -> bool:
|
|
||||||
|
from .pb import rpc_pb2
|
||||||
|
|
||||||
|
|
||||||
|
def signature_validator(pubkey: PublicKey, msg: rpc_pb2.Message) -> bool:
|
||||||
"""
|
"""
|
||||||
Verify the message against the given public key.
|
Verify the message against the given public key.
|
||||||
|
|
||||||
:param pubkey: the public key which signs the message.
|
:param pubkey: the public key which signs the message.
|
||||||
:param msg: the message signed.
|
:param msg: the message signed.
|
||||||
"""
|
"""
|
||||||
# TODO: Implement the signature validation
|
try:
|
||||||
|
pubkey.verify(msg.SerializeToString(), msg.signature)
|
||||||
|
except Exception:
|
||||||
|
return False
|
||||||
return True
|
return True
|
||||||
|
|||||||
Reference in New Issue
Block a user