Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | 7x 7x 4x 7x | import { useEffect, useState } from 'react';
import { Algorithms, hash } from '../utils/subtle-crypto';
/**
* Returns a hashed version of the value provided
* @param algorithm the hashing algorithm to use
* @param value the value to hash
* @returns the hashed value
* @see https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest#browser_compatibility
*/
export function useSubtleCrypto(
algorithm?: Algorithms,
value?: string | null,
defaultValue?: string
): string | undefined {
const [hashedValue, setHashedValue] = useState<string>(defaultValue);
useEffect(() => {
hash(algorithm, value, defaultValue).then(setHashedValue);
}, [algorithm, value]);
return hashedValue;
}
|