diff --git a/packages/common/lib/hasher.ts b/packages/common/lib/hasher.ts index 4a7e3d61..2b1d4c2b 100644 --- a/packages/common/lib/hasher.ts +++ b/packages/common/lib/hasher.ts @@ -5,12 +5,13 @@ const supportedAlgorithms = ['sha256', 'sha384', 'sha512'] as const; type SupportedAlgorithms = (typeof supportedAlgorithms)[number]; export const defaultHasher: Hasher = (data, algorithm) => { - if (!supportedAlgorithms.includes(algorithm as SupportedAlgorithms)) { + const sanitizedAlgorithm = algorithm.toLowerCase().replace(/[-_]/g, '') + if (!supportedAlgorithms.includes(sanitizedAlgorithm as SupportedAlgorithms)) { throw new Error(`Unsupported hashing algorithm ${algorithm}`); } return new Uint8Array( - sha(algorithm as SupportedAlgorithms) + sha(sanitizedAlgorithm as SupportedAlgorithms) .update(data) .digest(), );