Skip to content

Commit

Permalink
feat: Support lower version of nodejs in crypto (#48)
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas <Lukas@hopae.io>
  • Loading branch information
lukasjhan committed Jan 31, 2024
1 parent 67428a4 commit 6aa790c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ export const digest = async (
algorithm: string = 'SHA-256',
): Promise<string> => {
const Crypto = require('node:crypto');
const hash = Crypto.createHash(algorithm);
const nodeAlg = toNodeCryptoAlg(algorithm);
const hash = Crypto.createHash(nodeAlg);
hash.update(data);
return hash.digest('hex');
};

export const getHasher = (algorithm: string = 'SHA-256') => {
return (data: string) => digest(data, algorithm);
};

const toNodeCryptoAlg = (hashAlg: string): string =>
hashAlg.replace('-', '').toLowerCase();

0 comments on commit 6aa790c

Please sign in to comment.