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 (arrayBuffer: ArrayBuffer) => { // Compute the SHA-256 hash of the array buffer const hash = await sha256(arrayBuffer).catch((err) => { // Handle error if hashing fails console.log(`error occurred in hashing arrayBuffer :>> `, err) toast.error(err.message || `error occurred in hashing arrayBuffer`) return null // Return null if hashing fails }) return hash // Return the SHA-256 hash }