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

[transaction] Add ability to get transaction hash #345

Merged
merged 1 commit into from
Apr 5, 2024

Conversation

gregnazario
Copy link
Collaborator

Description

This adds the ability to get the transaction hash locally.

How it works is that all Rust structs are signed as follows:

  1. SHA3_256 Hash APTOS:: + StructName = prefix
  2. SHA3_256 Hash the above prefix + BCS encoded bytes of the struct

Note that, enums are encoded by a u8, followed by the actual bytes associated. So, in the case of the transaction hash, it must be a UserTransaction = 0 for the enum type before the rest of the bytes.

Resolves #321

Note this code, only hashes user transactions

Test Plan

E2E test ensures it's the same as the API

Related Links

@gregnazario gregnazario requested a review from a team as a code owner March 31, 2024 03:15
@gregnazario gregnazario requested a review from 0xmaayan March 31, 2024 03:19
Copy link
Collaborator

@0xmaayan 0xmaayan left a comment

Choose a reason for hiding this comment

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

LGTM.
Left some comments on naming.
Please update CHANGELOG

src/transactions/transactionBuilder/transactionBuilder.ts Outdated Show resolved Hide resolved
src/transactions/transactionBuilder/transactionBuilder.ts Outdated Show resolved Hide resolved
tests/e2e/transaction/transactionBuilder.test.ts Outdated Show resolved Hide resolved
src/transactions/transactionBuilder/transactionBuilder.ts Outdated Show resolved Hide resolved
@gregnazario gregnazario force-pushed the add-transaction-hashing branch from 9cfd74f to 9ddfaf0 Compare April 5, 2024 01:39
@gregnazario gregnazario merged commit 5cec8ce into main Apr 5, 2024
8 checks passed
@gregnazario gregnazario deleted the add-transaction-hashing branch April 5, 2024 18:04
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.

[Feature Request] Add an API to compute TX hash
2 participants