-
Notifications
You must be signed in to change notification settings - Fork 18
feat: add sha384, sha512 support #282
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
Conversation
Signed-off-by: Lukas.J Han <[email protected]>
Signed-off-by: Lukas J Han <[email protected]>
Signed-off-by: Lukas J Han <[email protected]>
Co-authored-by: Mirko Mollik <[email protected]> Signed-off-by: Lukas.J.Han <[email protected]>
Signed-off-by: Lukas.J.Han <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds SHA-384 and SHA-512 support alongside the existing SHA-256 implementation.
- Introduces
sha384
andsha512
functions and extendshasher
to handle those algorithms. - Updates tests to compare all three algorithms against Node’s
crypto.createHash
. - Bumps the
@noble/hashes
dependency to^1.8.0
and re-exports from a consolidatedsha2.ts
.
Reviewed Changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
packages/hash/src/test/sha2.spec.ts | Renamed suite, added browser-skipped tests for SHA-256/384/512 on strings and ArrayBuffers |
packages/hash/src/sha2.ts | Added sha384 , sha512 and updated hasher with a switch; adjusted imports |
packages/hash/src/index.ts | Updated export from sha256 to sha2 |
packages/hash/package.json | Bumped @noble/hashes from 1.0.0 to ^1.8.0 |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (2)
packages/hash/src/sha2.ts:8
- The function currently accepts
ArrayBuffer
but normalizes toUint8Array
internally. Consider updating the signature to(text: string | Uint8Array)
to accurately reflect the input shape and avoid type mismatches.
export const sha256 = (text: string | ArrayBuffer): Uint8Array => {
packages/hash/src/test/sha2.spec.ts:128
- There’s no test covering an unsupported algorithm in
hasher
. Adding a test that callshasher(data, 'invalid-algo')
and expects theUnsupported algorithm
exception would ensure correct error handling.
describe('Hash', () => {
@lukasjhan I think when we rename the one file + make clear that someone could also use their own hasher implementation, than this PR is fine. |
Signed-off-by: Lukas J Han <[email protected]>
Signed-off-by: Lukas J Han <[email protected]>
Signed-off-by: Lukas J Han <[email protected]>
Signed-off-by: Mirko Mollik <[email protected]>
No description provided.