Add SignedTransaction.hash() to v1 and v2 SDKs - #119
Merged
Conversation
Expose the committed transaction hash from a signed transaction before submission, matching the Aptos Transaction/UserTransaction hashing scheme used by the Go and TypeScript SDKs. Co-authored-by: Greg Nazario <greg@gnazar.io>
Co-authored-by: Greg Nazario <greg@gnazar.io>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #119 +/- ##
==========================================
+ Coverage 93.19% 93.20% +0.01%
==========================================
Files 56 56
Lines 5172 5183 +11
==========================================
+ Hits 4820 4831 +11
Misses 352 352
🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a SignedTransaction.hash() helper to both the v1 and v2 Aptos Python SDK surfaces so callers can deterministically compute the Aptos transaction hash for a signed user transaction before submitting it to the network.
Changes:
- Added
SignedTransaction.hash()for v1 (aptos_sdk.transactions.SignedTransaction) using the AptosTransaction/UserTransactionhashing scheme (APTOS::Transactiondomain separator + variant byte + BCS bytes). - Added
SignedTransaction.hash()for v2 (aptos_sdk_v2.transactions.SignedTransactionand theaptos_sdk.v2mirror) with the same hashing scheme. - Added unit tests in both v1 and v2 asserting a known, deterministic hash vector.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
aptos_sdk/transactions.py |
Adds v1 SignedTransaction.hash() plus a corpus-based unit test verifying a known hash output. |
v2/src/aptos_sdk_v2/transactions/signed_transaction.py |
Adds v2 SignedTransaction.hash() implementation (prehash + variant + BCS bytes, SHA3-256). |
aptos_sdk/v2/transactions/signed_transaction.py |
Mirrors the same v2 SignedTransaction.hash() implementation on the embedded aptos_sdk.v2 surface. |
v2/tests/unit/test_transactions.py |
Adds a v2 unit test validating the signed-transaction hash against a fixed corpus vector. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Addresses the feature request to compute a transaction hash from a
SignedTransactionbefore submitting it to the network (moved from aptos-labs/aptos-core#10999).Adds
SignedTransaction.hash()to both SDK surfaces:aptos_sdk.transactions.SignedTransactionaptos_sdk_v2.transactions.SignedTransaction(and the embeddedaptos_sdk.v2mirror)The hash follows the Aptos
Transaction/UserTransactionscheme used by the Go and TypeScript SDKs:SHA3-256("APTOS::Transaction")domain separator0x00user-transaction variant byteSignedTransactionbytesSHA3-256over the concatenation, returned as a0x-prefixed hex stringTest Plan
test_signed_transaction_hashinaptos_sdk/transactions.py(v1 unittest corpus)test_signed_txn_hashinv2/tests/unit/test_transactions.pymake fmt,make lint, v2ruff/mypy, and the new unit tests locallyRelated Links