Skip to content

Conversation

@AubreyDDD
Copy link
Contributor

@AubreyDDD AubreyDDD commented Dec 12, 2025

Description:

Allow both PrivateKey and PublicKey for batch_key in Transaction class, enabling more flexible batch transaction workflows.

Related issue(s):

Fixes #1015

Notes for reviewer:

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

Summary by CodeRabbit

  • New Features
    • Batch transactions now support PublicKey as the batch_key parameter, expanding beyond the previous PrivateKey-only requirement. This enables greater flexibility in transaction batching workflows and supports mixing both public and private keys within individual batch operations for more sophisticated transaction assembly and execution scenarios.

✏️ Tip: You can customize this high-level summary in your review settings.

Copilot AI review requested due to automatic review settings December 12, 2025 00:06
@github-actions
Copy link

Hi, this is WorkflowBot.
Your pull request cannot be merged as it is not passing all our workflow checks.
Please click on each check to review the logs and resolve issues so all checks pass.
To help you:

@AubreyDDD AubreyDDD changed the title support public for batch_key in Transaction fix: support public for batch_key in Transaction Dec 12, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR extends the Transaction class to support both PrivateKey and PublicKey for the batch_key parameter, enabling more flexible batch transaction workflows. Previously, only PrivateKey was accepted, which required users to have access to private keys even when only public key verification was needed.

Key changes:

  • Updated type annotations from PrivateKey to Key (Union type) for batch_key throughout Transaction class
  • Modified protobuf conversion to use the centralized key_to_proto utility function
  • Added comprehensive unit tests verifying both key types work correctly

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
tests/unit/test_batch_key.py New test file with unit tests verifying batch_key accepts both PrivateKey and PublicKey types
src/hiero_sdk_python/transaction/transaction.py Updated batch_key type annotation from PrivateKey to Key, changed protobuf conversion to use key_to_proto utility, updated method signatures and documentation
CHANGELOG.md Added entry documenting the change to allow PublicKey for batch_key in Transaction

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@exploreriii
Copy link
Contributor

Request review if available @hiero-ledger/hiero-sdk-python-triage

Copy link
Contributor

@exploreriii exploreriii left a comment

Choose a reason for hiding this comment

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

Hello @AubreyDDD
You may also want to expand eg

examples/transaction/batch_transaction.py
tests/integration/batch_transaction_e2e_test.py
tests/unit/test_batch_transaction.py

@exploreriii exploreriii marked this pull request as draft December 12, 2025 15:37
@AubreyDDD AubreyDDD marked this pull request as ready for review December 12, 2025 18:59
@exploreriii
Copy link
Contributor

Request review if available @hiero-ledger/hiero-sdk-python-triage

@exploreriii
Copy link
Contributor

Hi @AubreyDDD
You have this test that is failing, let us know if you need help
→ Check the integration test logs above for details.
tests/integration/batch_transaction_e2e_test.py::test_batch_transaction_set_batch_key_with_public_key FAILED [ 17%]
FAILED tests/integration/batch_transaction_e2e_test.py::test_batch_transaction_set_batch_key_with_public_key - hiero_sdk_python.exceptions.PrecheckError: Transaction failed precheck with status: INVALID_SIGNATURE (7), transaction ID: [email protected]

@github-actions
Copy link

Hi, this is MergeConflictBot.
Your pull request cannot be merged because it contains merge conflicts.

Please resolve these conflicts locally and push the changes.

To assist you, please read:

Thank you for contributing!

From the Hiero Python SDK Team

@AubreyDDD
Copy link
Contributor Author

I merged all tests into test_batch_transaction.py as suggested. The integration tests have the correct logic now but I can't verify locally due to SSL certificate issues. CI should validate them properly.

@github-actions
Copy link

Hello, this is the Office Hour Bot.

This is a reminder that the Hiero Python SDK Office Hours are scheduled in approximately 4 hours (14:00 UTC).

This session provides an opportunity to ask questions regarding this Pull Request or receive assistance from a maintainer.

Details:

Disclaimer: This is an automated reminder. Please verify the schedule here to be notified of any changes.

@exploreriii
Copy link
Contributor

Request review if available @hiero-ledger/hiero-sdk-python-triage

@exploreriii
Copy link
Contributor

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Dec 17, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@exploreriii exploreriii added the p1 High priority, needed soon label Dec 17, 2025
@coderabbitai
Copy link

coderabbitai bot commented Dec 17, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

This pull request adds support for using PublicKey as a batch_key in batch transactions, extending the previous requirement of PrivateKey only. The implementation updates type annotations from PrivateKey to a broader Key type (union of PrivateKey and PublicKey), modifies the key serialization logic to use a general key_to_proto utility, and adds comprehensive unit and integration tests demonstrating the feature.

Changes

Cohort / File(s) Summary
Core Implementation
src/hiero_sdk_python/transaction/transaction.py
Updated batch_key type annotation from Optional[PrivateKey] to Optional[Key]. Modified set_batch_key() and batchify() method signatures to accept Key instead of PrivateKey. Changed batch key serialization in build_base_transaction_body() to use key_to_proto(self.batch_key) instead of self.batch_key.public_key()._to_proto(). Added import for Key and key_to_proto from hiero_sdk_python.utils.key_utils.
Tests
tests/unit/batch_transaction_test.py, tests/integration/batch_transaction_e2e_test.py
Added unit tests validating set_batch_key() and batchify() with PublicKey, mixed PrivateKey/PublicKey scenarios, type annotations, and default values. Added integration tests confirming batch transactions execute correctly with PublicKey as batch_key, including mixed-key scenarios and verification of inner transaction receipts.
Documentation & Examples
examples/transaction/batch_transaction.py, CHANGELOG.md
Added perform_batch_tx_with_public_key() function demonstrating batch transaction usage with PublicKey as batch_key. Updated main flow to execute both PrivateKey and PublicKey batch demonstrations with progress reporting. Updated CHANGELOG.md documenting the feature addition.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Areas requiring attention:

  • Verify the key_to_proto() utility correctly serializes both PrivateKey and PublicKey to proto format without behavioral differences.
  • Confirm all test cases adequately cover edge cases with mixed key types and both inner and outer transaction signing scenarios.
  • Ensure the type broadening from PrivateKey to Key doesn't inadvertently allow invalid key types or create type-checking issues elsewhere in the codebase.

Poem

🐰 A rabbit hops with glee, the batch keys now run free,
Both public and private, a unified decree,
No more PrivateKey chains, the API's more sane,
With key_to_proto magic, consistency we gain!
wiggles nose

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: support public for batch_key in Transaction' directly summarizes the main change: enabling PublicKey support for batch_key in the Transaction class.
Linked Issues check ✅ Passed All coding requirements from issue #1015 are implemented: batch_key type updated to accept Key type, methods updated, build_base_transaction_body uses key_to_proto, and comprehensive tests added for PublicKey support.
Out of Scope Changes check ✅ Passed Changes are focused and scoped to the batch_key feature: core Transaction class updates, example demonstration, and comprehensive test coverage directly address the linked issue objectives.
Docstring Coverage ✅ Passed Docstring coverage is 95.45% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d3201de and 54af4ed.

📒 Files selected for processing (5)
  • CHANGELOG.md (1 hunks)
  • examples/transaction/batch_transaction.py (3 hunks)
  • src/hiero_sdk_python/transaction/transaction.py (5 hunks)
  • tests/integration/batch_transaction_e2e_test.py (2 hunks)
  • tests/unit/batch_transaction_test.py (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
src/hiero_sdk_python/transaction/transaction.py (1)
src/hiero_sdk_python/utils/key_utils.py (1)
  • key_to_proto (18-48)
examples/transaction/batch_transaction.py (2)
src/hiero_sdk_python/crypto/private_key.py (2)
  • PrivateKey (14-471)
  • public_key (305-309)
src/hiero_sdk_python/transaction/transaction.py (1)
  • batchify (825-840)
tests/unit/batch_transaction_test.py (4)
src/hiero_sdk_python/crypto/private_key.py (2)
  • public_key (305-309)
  • PrivateKey (14-471)
src/hiero_sdk_python/crypto/public_key.py (1)
  • PublicKey (22-556)
src/hiero_sdk_python/transaction/transaction.py (2)
  • set_batch_key (811-823)
  • batchify (825-840)
src/hiero_sdk_python/transaction/batch_transaction.py (1)
  • BatchTransaction (19-164)
tests/integration/batch_transaction_e2e_test.py (3)
src/hiero_sdk_python/crypto/public_key.py (1)
  • PublicKey (22-556)
src/hiero_sdk_python/transaction/transaction.py (4)
  • batchify (825-840)
  • freeze_with (273-308)
  • sign (169-208)
  • set_batch_key (811-823)
src/hiero_sdk_python/transaction/batch_transaction.py (3)
  • BatchTransaction (19-164)
  • add_inner_transaction (55-69)
  • get_inner_transaction_ids (71-82)
🪛 Ruff (0.14.8)
tests/unit/batch_transaction_test.py

372-372: Unused function argument: mock_client

(ARG001)

tests/integration/batch_transaction_e2e_test.py

358-358: Redefinition of unused env from line 15

(F811)


399-399: Redefinition of unused env from line 15

(F811)


467-467: Redefinition of unused env from line 15

(F811)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: build-and-test (3.10)
  • GitHub Check: build-and-test (3.13)
  • GitHub Check: build-and-test (3.12)
  • GitHub Check: build-and-test (3.11)
  • GitHub Check: changelog-check
  • GitHub Check: run-examples
  • GitHub Check: coverage
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (19)
CHANGELOG.md (1)

60-60: LGTM!

The changelog entry correctly documents the new PublicKey support for batch_key in the Transaction class under the "Changed" section.

tests/integration/batch_transaction_e2e_test.py (4)

5-5: LGTM!

Necessary import for PublicKey to support type assertions in the new tests.


358-396: Good test coverage for PublicKey as batch_key.

This test properly validates:

  • Using PublicKey in batchify()
  • Type verification with isinstance check
  • Signing the batch with the corresponding PrivateKey
  • Full execution and receipt verification

The test correctly demonstrates the intended use case where a PublicKey is used for batch_key identification while the PrivateKey is used for signing.


399-464: Comprehensive mixed-key scenario test.

Good coverage of the mixed PrivateKey/PublicKey use case with:

  • First transaction using PrivateKey directly
  • Second and third transactions using PublicKey
  • Type assertions for each inner transaction's batch_key
  • Proper signing with all corresponding PrivateKeys
  • Verification of all inner transaction receipts

467-506: Validates set_batch_key with PublicKey.

This test covers the alternative workflow using set_batch_key() directly instead of batchify(), ensuring both APIs work correctly with PublicKey.

examples/transaction/batch_transaction.py (3)

165-167: LGTM!

Good clarification that this function demonstrates the PrivateKey workflow, distinguishing it from the new PublicKey demonstration.


207-256: Well-structured demonstration of PublicKey batch_key support.

The example clearly shows:

  • Generating a key pair and using the PublicKey as batch_key
  • Creating inner transactions with batchify(client, batch_public_key)
  • Signing the outer batch with the corresponding PrivateKey
  • Helpful print statements explaining the workflow

This provides users with a concrete reference implementation.


282-314: Good end-to-end demonstration flow.

The updated main() properly demonstrates both workflows sequentially with clear visual separation, helping users understand both use cases.

tests/unit/batch_transaction_test.py (7)

18-18: LGTM!

Necessary import for PublicKey type assertions in the new tests.


372-390: Good basic test for PublicKey acceptance.

Verifies that set_batch_key() correctly accepts and stores a PublicKey.

Note: The static analysis warning about unused mock_client is a false positive - while not directly used in this specific test, the fixture parameter ensures proper test isolation and may be used by the fixture chain.


393-411: Good test for batchify with PublicKey.

Validates that batchify() works correctly with PublicKey and properly freezes the transaction.


414-447: Good coverage testing both Ed25519 and ECDSA key types.

Using different key algorithms (Ed25519 and ECDSA) ensures the PublicKey support works regardless of the underlying cryptographic algorithm.


450-481: Good mixed-key scenario test.

Properly validates that BatchTransaction can contain inner transactions with both PrivateKey and PublicKey batch_keys simultaneously.


484-504: Good setter tests with method chaining verification.

Both tests verify that set_batch_key() works with either key type and properly supports method chaining.


507-525: Good type annotation and default value tests.

These tests verify the type flexibility and ensure batch_key defaults to None as expected.

src/hiero_sdk_python/transaction/transaction.py (4)

19-19: LGTM!

Correct import of Key type alias and key_to_proto utility from the new key_utils module. This enables the flexible handling of both PrivateKey and PublicKey for batch_key.


69-69: LGTM!

Type annotation correctly updated to Optional[Key] to accept both PrivateKey and PublicKey.


437-438: LGTM!

Good use of the key_to_proto() utility which handles both PrivateKey and PublicKey correctly:

  • For PrivateKey: extracts public key first, then converts to proto
  • For PublicKey: converts directly to proto

This is cleaner than the previous approach of calling self.batch_key.public_key()._to_proto().


825-839: LGTM!

The batchify method correctly accepts Key type for batch_key, enabling workflows where only the PublicKey is available at batch construction time.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@manishdait
Copy link
Contributor

Hi @AubreyDDD, Please resolve merge conflicts and update the branch

@exploreriii exploreriii marked this pull request as draft December 18, 2025 13:46
@AubreyDDD AubreyDDD marked this pull request as ready for review December 19, 2025 05:54
@codecov
Copy link

codecov bot commented Dec 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1051   +/-   ##
=======================================
  Coverage   91.19%   91.19%           
=======================================
  Files         139      139           
  Lines        8446     8447    +1     
=======================================
+ Hits         7702     7703    +1     
  Misses        744      744           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@exploreriii exploreriii merged commit 3241d95 into hiero-ledger:main Dec 19, 2025
22 checks passed
@exploreriii
Copy link
Contributor

Congratulations Aubrey! Nicely documented, very clear and thorough
Thank you!

prajeeta15 pushed a commit to prajeeta15/hiero-sdk-python that referenced this pull request Dec 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p1 High priority, needed soon

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support PublicKey for batch_key in Transaction

4 participants