mirror of
https://github.com/fluencelabs/js-libp2p-crypto
synced 2025-04-28 05:42:29 +00:00
22 lines
399 B
JavaScript
22 lines
399 B
JavaScript
'use strict'
|
|
|
|
const crypto = require('crypto')
|
|
const lengths = require('./lengths')
|
|
|
|
exports.create = function (hash, secret, callback) {
|
|
const res = {
|
|
digest (data, cb) {
|
|
const hmac = crypto.createHmac(hash.toLowerCase(), secret)
|
|
|
|
hmac.update(data)
|
|
|
|
setImmediate(() => {
|
|
cb(null, hmac.digest())
|
|
})
|
|
},
|
|
length: lengths[hash]
|
|
}
|
|
|
|
callback(null, res)
|
|
}
|