Skip to content

Instantly share code, notes, and snippets.

@DanielFGray
Created April 3, 2019 18:02
Show Gist options
  • Save DanielFGray/b59550d600db0543a676e2984b288fe0 to your computer and use it in GitHub Desktop.
Save DanielFGray/b59550d600db0543a676e2984b288fe0 to your computer and use it in GitHub Desktop.
promise wrapper around crypto.createHash
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