16 lines
397 B
TypeScript
16 lines
397 B
TypeScript
import { createHash } from 'node:crypto'
|
|
|
|
/**
|
|
* Compute SHA-256 hash and return raw Buffer.
|
|
*/
|
|
export const sha256 = (data: string | Buffer): Buffer => {
|
|
return createHash('sha256').update(data).digest()
|
|
}
|
|
|
|
/**
|
|
* Compute SHA-256 hash and return lowercase hex string.
|
|
*/
|
|
export const sha256Hex = (data: string | Buffer): string => {
|
|
return createHash('sha256').update(data).digest('hex')
|
|
}
|