Skip to content

Commit

Permalink
Add signature validation method
Browse files Browse the repository at this point in the history
Signed-off-by: Leonid Lygin <ionagamed@gmail.com>
  • Loading branch information
ionagamed authored and Igor Egorov committed Dec 27, 2019
1 parent abb7ad0 commit 6ba48ad
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions iroha/iroha.py
Expand Up @@ -102,6 +102,23 @@ def sign_query(query, private_key):
query.signature.CopyFrom(signature)
return query

@staticmethod
def is_signature_valid(message, signature):
"""
Verify signature validity.
:param signature: the signature to be checked
:param message: message to check the signature against
:return: bool, whether the signature is valid for the message
"""
message_hash = IrohaCrypto.hash(message)
try:
signature_bytes = binascii.unhexlify(signature.signature)
public_key = binascii.unhexlify(signature.public_key)
ed25519.checkvalid(signature_bytes, message_hash, public_key)
return True
except (ed25519.SignatureMismatch, ValueError):
return False

@staticmethod
def reduced_hash(transaction):
"""
Expand Down

0 comments on commit 6ba48ad

Please sign in to comment.