Created
April 3, 2019 18:02
-
-
Save DanielFGray/b59550d600db0543a676e2984b288fe0 to your computer and use it in GitHub Desktop.
promise wrapper around crypto.createHash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const crypto = require('crypto') | |
module.exports = function hash({ method }, input) { | |
return new Promise((res, rej) => { | |
const h = crypto.createHash(method) | |
h.on('readable', () => { | |
const data = h.read() | |
if (data) { | |
res(data.toString('hex')) | |
} else rej() | |
}) | |
h.write(input) | |
h.end() | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment