feat: Add optimized sha512 and sha384 utilities - #305
Conversation
|
|
||
| describe('sha256', () => { | ||
| const isNode18 = parse(process.version)?.major === 18; | ||
| describe('hash functions', () => { |
There was a problem hiding this comment.
I would recommend reviewing without white-space diffs, since I changed the nesting here
| // 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, | ||
| }); | ||
| } | ||
| }); |
There was a problem hiding this comment.
Maybe just restore the original globalThis.crypto.subtle in afterEach?
There was a problem hiding this comment.
We still need to force restore digest though
There was a problem hiding this comment.
I guess defineProperty overrides it somehow? Without it, the tests fall into the Noble path every time.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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.

Add optimized
sha512andsha384utilities that follow the same pattern as thesha256function.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
sha512andsha384helpers inhashing.ts, mirroringsha256: prefercrypto.subtle.digestwhen 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/afterEachthat restores mockedcrypto.subtleafter each case. CHANGELOG and package export snapshot tests now listsha512andsha384.Reviewed by Cursor Bugbot for commit c92144d. Bugbot is set up for automated code reviews on this repo. Configure here.