Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding method to verify signature on SignedTransaction object #308

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions algosdk/future/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -2145,6 +2145,35 @@ def get_txid(self):
"""
return self.transaction.get_txid()

def verify_signature(self):
"""
Verify the signature on the transaction is valid
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Verify the signature on the transaction is valid
Verify that the signature on the transaction is valid.


Returns:
bool: whether or not the signature is valid
"""

if self.signature is None or len(self.signature) == 0:
# TODO: exception?
return False

public_key = self.transaction.sender
if self.authorizing_address is not None:
public_key = self.authorizing_address

verify_key = VerifyKey(encoding.decode_address(public_key))

prefixed_message = constants.TXID_PREFIX + base64.b64decode(
encoding.msgpack_encode(self.transaction)
)
try:
verify_key.verify(
prefixed_message, base64.b64decode(self.signature)
)
return True
except BadSignatureError:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think nacl's VerifyKey API can now return a TypeError or ValueError. The multisig/logicsig verify in the Python SDK doesn't catch these errors yet either so I think it would be nice to update them :D

return False

def dictify(self):
od = OrderedDict()
if self.signature:
Expand Down