Files
js-libp2p-crypto/src/hmac/index.js
Jacob Heun c54ea206f0 feat: nextTick instead of setImmediate, and fix sync in async (#136)
* fix: avoid sync callback in async function

* chore: fix linting

* chore: remove non jenkins ci

* refactor: use nextTick over setImmediate

* refactor: async/nextTick for better browser support
2019-01-03 16:13:07 +00:00

23 lines
438 B
JavaScript

'use strict'
const crypto = require('crypto')
const lengths = require('./lengths')
const nextTick = require('async/nextTick')
exports.create = function (hash, secret, callback) {
const res = {
digest (data, cb) {
const hmac = crypto.createHmac(hash.toLowerCase(), secret)
hmac.update(data)
nextTick(() => {
cb(null, hmac.digest())
})
},
length: lengths[hash]
}
callback(null, res)
}