Skip to content

feat: Add optimized sha512 and sha384 utilities - #305

Merged
FrederikBolding merged 6 commits into
mainfrom
fb/add-more-sha-functions
Aug 27, 2026
Merged

feat: Add optimized sha512 and sha384 utilities#305
FrederikBolding merged 6 commits into
mainfrom
fb/add-more-sha-functions

Conversation

@FrederikBolding

@FrederikBolding FrederikBolding commented Aug 27, 2026

Copy link
Copy Markdown
Member

Add optimized sha512 and sha384 utilities that follow the same pattern as the sha256 function.


Note

Medium Risk
New cryptographic digest APIs in a shared utils package; behavior follows the existing sha256 pattern with parity tests, but incorrect fallbacks would affect downstream crypto use.

Overview
Adds public sha512 and sha384 helpers in hashing.ts, mirroring sha256: prefer crypto.subtle.digest when available and fall back to @noble/hashes/sha512.

Test coverage expands with the same digest vectors and noble fallback cases for both new functions. The hashing tests are reorganized under a shared beforeEach/afterEach that restores mocked crypto.subtle after each case. CHANGELOG and package export snapshot tests now list sha512 and sha384.

Reviewed by Cursor Bugbot for commit c92144d. Bugbot is set up for automated code reviews on this repo. Configure here.

Comment thread src/hashing.test.ts

describe('sha256', () => {
const isNode18 = parse(process.version)?.major === 18;
describe('hash functions', () => {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I would recommend reviewing without white-space diffs, since I changed the nesting here

@FrederikBolding
FrederikBolding marked this pull request as ready for review August 27, 2026 10:57
Comment thread src/hashing.test.ts Outdated
Comment on lines 25 to 36
// Restore digest if previous tests broke it
if (!globalThis.crypto.subtle?.digest) {
Object.defineProperty(globalThis.crypto, 'subtle', {
value: originalSubtle,
writable: true,
});
Object.defineProperty(globalThis.crypto.subtle, 'digest', {
value: originalDigest,
writable: true,
});
}
});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe just restore the original globalThis.crypto.subtle in afterEach?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We still need to force restore digest though

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How come?

@FrederikBolding FrederikBolding Aug 27, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I guess defineProperty overrides it somehow? Without it, the tests fall into the Noble path every time.

@FrederikBolding
FrederikBolding requested a review from Mrtenz August 27, 2026 11:34

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 0e65dac. Configure here.

Comment thread src/hashing.test.ts
@cursor
cursor Bot requested a review from ccharly August 27, 2026 11:39
@FrederikBolding
FrederikBolding merged commit 5e5d015 into main Aug 27, 2026
49 of 57 checks passed
@FrederikBolding
FrederikBolding deleted the fb/add-more-sha-functions branch August 27, 2026 11:54
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.

2 participants