Skip to content

Commit 6ba48ad

Browse files
ionagamedIgor Egorov
authored andcommitted
Add signature validation method
Signed-off-by: Leonid Lygin <[email protected]>
1 parent abb7ad0 commit 6ba48ad

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

iroha/iroha.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,23 @@ def sign_query(query, private_key):
102102
query.signature.CopyFrom(signature)
103103
return query
104104

105+
@staticmethod
106+
def is_signature_valid(message, signature):
107+
"""
108+
Verify signature validity.
109+
:param signature: the signature to be checked
110+
:param message: message to check the signature against
111+
:return: bool, whether the signature is valid for the message
112+
"""
113+
message_hash = IrohaCrypto.hash(message)
114+
try:
115+
signature_bytes = binascii.unhexlify(signature.signature)
116+
public_key = binascii.unhexlify(signature.public_key)
117+
ed25519.checkvalid(signature_bytes, message_hash, public_key)
118+
return True
119+
except (ed25519.SignatureMismatch, ValueError):
120+
return False
121+
105122
@staticmethod
106123
def reduced_hash(transaction):
107124
"""

0 commit comments

Comments
 (0)