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

Implement Hash trait for Bytes and String types #5089

Merged
merged 4 commits into from Sep 5, 2023
Merged

Conversation

bitzoic
Copy link
Member

@bitzoic bitzoic commented Sep 5, 2023

Description

The current Hasher implementation uses the sha256() and keccak256() functions provided in the Bytes type implementation.

This PR moves the assembly block that does the hashing into the Hasher. This allows for the homogenous syntax of hashing any type and moves all hashing into the hash.sw file.
This PR also implements the Hash trait for the Bytes and String types.

Before:

assert(sha256(my_string) == my_bytes.sha256());

After:

assert(sha256(my_string) == sha256(my_bytes));

Checklist

  • I have linked to any relevant issues.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation where relevant (API docs, the reference, and the Sway book).
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added (or requested a maintainer to add) the necessary Breaking* or New Feature labels where relevant.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@bitzoic bitzoic added lib: std Standard library breaking May cause existing user code to break. Requires a minor or major release. labels Sep 5, 2023
@bitzoic bitzoic requested review from esdrubal and a team September 5, 2023 08:56
@bitzoic bitzoic self-assigned this Sep 5, 2023
esdrubal
esdrubal previously approved these changes Sep 5, 2023
Copy link
Contributor

@esdrubal esdrubal left a comment

Choose a reason for hiding this comment

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

LGTM!

@bitzoic bitzoic enabled auto-merge (squash) September 5, 2023 11:03
sway-lib-std/src/hash.sw Show resolved Hide resolved
sway-lib-std/src/hash.sw Show resolved Hide resolved
sway-lib-std/src/hash.sw Show resolved Hide resolved
sway-lib-std/src/string.sw Show resolved Hide resolved
@bitzoic bitzoic merged commit 49ee268 into master Sep 5, 2023
32 checks passed
@bitzoic bitzoic deleted the bitzoic-hash branch September 5, 2023 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking May cause existing user code to break. Requires a minor or major release. lib: std Standard library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants