mirror of
https://github.com/fluencelabs/js-libp2p-crypto
synced 2025-07-23 04:22:09 +00:00
* 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
23 lines
438 B
JavaScript
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)
|
|
}
|