Skip to content

Add SignedTransaction.hash() to v1 and v2 SDKs - #119

Merged
gregnazario merged 2 commits into
mainfrom
cursor/signed-transaction-hash-1924
Jun 18, 2026
Merged

Add SignedTransaction.hash() to v1 and v2 SDKs#119
gregnazario merged 2 commits into
mainfrom
cursor/signed-transaction-hash-1924

Conversation

@gregnazario

Copy link
Copy Markdown
Contributor

Description

Addresses the feature request to compute a transaction hash from a SignedTransaction before submitting it to the network (moved from aptos-labs/aptos-core#10999).

Adds SignedTransaction.hash() to both SDK surfaces:

  • v1: aptos_sdk.transactions.SignedTransaction
  • v2: aptos_sdk_v2.transactions.SignedTransaction (and the embedded aptos_sdk.v2 mirror)

The hash follows the Aptos Transaction / UserTransaction scheme used by the Go and TypeScript SDKs:

  1. SHA3-256("APTOS::Transaction") domain separator
  2. 0x00 user-transaction variant byte
  3. BCS-serialized SignedTransaction bytes
  4. SHA3-256 over the concatenation, returned as a 0x-prefixed hex string

Test Plan

  • Added test_signed_transaction_hash in aptos_sdk/transactions.py (v1 unittest corpus)
  • Added test_signed_txn_hash in v2/tests/unit/test_transactions.py
  • Both tests assert a deterministic hash against a known signed-transaction corpus vector
  • Ran make fmt, make lint, v2 ruff/mypy, and the new unit tests locally

Related Links

Open in Web Open in Cursor 

cursoragent and others added 2 commits June 17, 2026 13:50
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

codecov Bot commented Jun 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.20%. Comparing base (f8ef5dc) to head (36887a6).

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              
Flag Coverage Δ
v1-sdk 90.36% <100.00%> (+0.01%) ⬆️
v2-sdk 97.02% <100.00%> (+<0.01%) ⬆️
Files with missing lines Coverage Δ
aptos_sdk/transactions.py 94.86% <100.00%> (+0.07%) ⬆️
...rc/aptos_sdk_v2/transactions/signed_transaction.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gregnazario
gregnazario requested a review from Copilot June 17, 2026 14:12
@gregnazario
gregnazario marked this pull request as ready for review June 17, 2026 14:12
@gregnazario
gregnazario requested a review from a team as a code owner June 17, 2026 14:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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 Aptos Transaction/UserTransaction hashing scheme (APTOS::Transaction domain separator + variant byte + BCS bytes).
  • Added SignedTransaction.hash() for v2 (aptos_sdk_v2.transactions.SignedTransaction and the aptos_sdk.v2 mirror) 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.

@gregnazario
gregnazario merged commit 20b8faa into main Jun 18, 2026
14 checks passed
@gregnazario
gregnazario deleted the cursor/signed-transaction-hash-1924 branch June 18, 2026 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants