Skip to content

Add AccountInfoFlow to verify signatures against an account's key #2786

Open

Description

@danielmarv

🐞 Problem Description

To check that a signature (or a signed transaction) really comes from a given Hedera account, a user has to:

  1. Run an AccountInfoQuery to get the account's current key.
  2. Make sure that key is a single PublicKey and not a KeyList or threshold key.
  3. Verify the signature against that key.

The Java and JS SDKs wrap these steps in AccountInfoFlow (verifySignature / verifyTransactionSignature). The Python SDK has no equivalent.

There is a second gap. PublicKey has verify(signature, data), but nothing that checks a Transaction's signatures against the key (Java has PublicKey.verifyTransaction). The flow needs it, and it is also useful on its own.

💡 Expected Solution

from hiero_sdk_python import AccountInfoFlow

ok = AccountInfoFlow.verify_signature(client, account_id, message, signature)
ok = AccountInfoFlow.verify_transaction_signature(client, account_id, signed_tx)

🛠️ Implementation Notes

  • Add src/hiero_sdk_python/account/account_info_flow.py with an AccountInfoFlow class that only has static methods:
    @staticmethod
    def verify_signature(client: Client, account_id: AccountId, message: bytes, signature: bytes) -> bool: ...
    
    @staticmethod
    def verify_transaction_signature(client: Client, account_id: AccountId, transaction: Transaction) -> bool: ...
  • Add a private helper _get_account_public_key(client, account_id) -> PublicKey. It runs AccountInfoQuery().set_account_id(account_id).execute(client) and returns info.key if it is a PublicKey. If the key is a KeyList, a threshold key, a contract ID key or missing, raise a clear error that names the account. Java does the same with UnsupportedOperationException.
  • PublicKey.verify() currently raises InvalidSignature and returns None. The flow methods should return bool: True when the signature is valid, False when it is not. Any other error (network, precheck, unsupported key) should still propagate.
  • Add PublicKey.verify_transaction(transaction: Transaction) -> bool:
    • The transaction must be frozen.
    • For every body in transaction._signature_map (one per node), find the SignaturePair whose pubKeyPrefix matches this key and verify it over the body bytes.
    • Return True only if every node body has a valid signature from this key.
    • Look at the Java PublicKey.verifyTransaction for the exact rules. Reuse Transaction.get_signatures() if it fits.
  • Export AccountInfoFlow from hiero_sdk_python/__init__.py.
  • Add an example at examples/account/account_info_flow.py that signs a message and a transaction with an account's key and verifies both.

Async variants are out of scope.

🧪 Testing

  • Unit tests for PublicKey.verify_transaction: ED25519 and ECDSA keys, a valid signature, a wrong key, a tampered body, a transaction that isn't frozen, and multiple nodes where only some bodies are signed.
  • Unit tests for AccountInfoFlow with a mocked AccountInfoQuery: valid and invalid signatures, and the KeyList / missing key error paths.
  • Integration test: create an account, sign a message and a transaction with its key, and verify both through the flow. A signature from a different key must return False.

✅ Acceptance Criteria

  • AccountInfoFlow.verify_signature and AccountInfoFlow.verify_transaction_signature are available and return bool
  • PublicKey.verify_transaction is added
  • Unsupported account key types raise a clear error
  • Unit and integration tests pass, and an example is added

📚 References

Activity

  1. added
    skill: intermediaterequires some knowledge of the codebase with some defined steps to implement or examples
    scope: DLTinvolves engineering for distributed ledger technology
    pythonPull requests that update python code
    on Nov 12, 2026
  2. github-actions commented on Nov 12, 2026

    @github-actions

    Thanks for your submission.

    This issue is awaiting approval from @hiero-ledger/hiero-sdk-python-triage and @hiero-ledger/hiero-sdk-python-committers and @hiero-ledger/hiero-sdk-python-maintainers.

  3. locked as off topic and limited conversation to collaborators on Nov 12, 2026
  4. added
    approvedIssue has been approved by team member
    and removed on Nov 13, 2026
  5. unlocked this conversation on Nov 13, 2026
  6. github-actions commented on Nov 13, 2026

    @github-actions

    Approved by @hiero-ledger/hiero-sdk-python-triage and @hiero-ledger/hiero-sdk-python-committers and @hiero-ledger/hiero-sdk-python-maintainers.

  7. github-actions commented on Nov 13, 2026

    @github-actions
  8. anchit-goel commented on Nov 13, 2026

    @anchit-goel
    Contributor

    /assign

  9. github-actions commented on Nov 21, 2026

    @github-actions

    Hi @anchit-goel 👋

    This issue has been assigned but no pull request has been created yet.
    Are you still planning on working on it?
    If you are, please create a draft PR linked to this issue or comment /working to let us know.
    If you're no longer able to work on this issue, you can comment /unassign to release it.

    From the Python SDK Team

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

approvedIssue has been approved by team memberpythonPull requests that update python codescope: DLTinvolves engineering for distributed ledger technologyskill: intermediaterequires some knowledge of the codebase with some defined steps to implement or examples

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions