sigit.io/src/utils/hash.ts
SwiftHawk d879c7d45a
All checks were successful
Release / build_and_release (push) Successful in 56s
feat: added hashes.json in zip
2024-04-22 16:24:50 +05:00

20 lines
710 B
TypeScript

import { sha256 } from 'crypto-hash'
import { toast } from 'react-toastify'
/**
* Computes the SHA-256 hash of an ArrayBuffer.
* @param arrayBuffer The ArrayBuffer to hash.
* @returns A Promise resolving to the SHA-256 hash as a hexadecimal string, or null if hashing fails.
*/
export const getHash = async (input: ArrayBuffer | string) => {
// Compute the SHA-256 hash of the array buffer
const hash = await sha256(input).catch((err) => {
// Handle error if hashing fails
console.log(`error occurred in hashing arrayBuffer :>> `, err)
toast.error(err.message || `error occurred in hashing`)
return null // Return null if hashing fails
})
return hash // Return the SHA-256 hash
}