feat: Add WebCrypto wrappers for SHA hashing - #10282
Merged
Merged
Conversation
FrederikBolding
marked this pull request as ready for review
September 21, 2026 08:21
FrederikBolding
enabled auto-merge
September 21, 2026 08:22
Mrtenz
reviewed
Sep 21, 2026
| * @param bytes - A byte array. | ||
| * @returns The SHA-256 hash as a byte array. | ||
| */ | ||
| export async function sha256( |
Member
There was a problem hiding this comment.
Do we not want a fallback in case WebCrypto is not available?
Member
Author
There was a problem hiding this comment.
My thinking with the cryptography package was to not have fallbacks. Instead expecting the clients have WebCrypto available.
Mrtenz
reviewed
Sep 21, 2026
Mrtenz
reviewed
Sep 21, 2026
Mrtenz
reviewed
Sep 21, 2026
Mrtenz
reviewed
Sep 21, 2026
Mrtenz
reviewed
Sep 21, 2026
Member
There was a problem hiding this comment.
If you change the functions to allow BufferSource, adding some tests with other byte array representations here would be good.
Also alphabetic sorting.
Mrtenz
approved these changes
Sep 21, 2026
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.
Explanation
Add wrappers for native SHA-256, SHA-512 and SHA-384 to
metamask/cryptography.References
Checklist
Note
Low Risk
Isolated new hashing wrappers over the platform Web Crypto API with unit tests; no changes to existing consumer auth or key-handling flows in this diff.
Overview
Replaces the
@metamask/cryptographyplaceholder with async SHA helpers (sha256,sha384,sha512) that wrapglobalThis.crypto.subtle.digestand accept anyBufferSource, returning digests asUint8Array. The package entrypoint now re-exports./sha.jsinstead of the sample greeter.Adds Jest coverage for each algorithm across
Uint8Array,ArrayBuffer, andDataViewinputs (using@metamask/utilsin tests only), documents the initial release in the changelog, and wires TypeScript project references plus the README dependency graph to@metamask/utils.Reviewed by Cursor Bugbot for commit 0465a77. Bugbot is set up for automated code reviews on this repo. Configure here.