mirror of
https://github.com/fluencelabs/js-libp2p-crypto
synced 2025-06-23 12:51:56 +00:00
25 lines
455 B
JavaScript
25 lines
455 B
JavaScript
![]() |
'use strict'
|
||
|
|
||
|
const crypto = require('crypto')
|
||
|
|
||
|
const lengths = require('./hmac-lengths')
|
||
|
|
||
|
exports.create = function (hash, secret, callback) {
|
||
|
const res = {
|
||
|
digest (data, cb) {
|
||
|
const hmac = genFresh()
|
||
|
hmac.update(data)
|
||
|
|
||
|
setImmediate(() => {
|
||
|
cb(null, hmac.digest())
|
||
|
})
|
||
|
},
|
||
|
length: lengths[hash]
|
||
|
}
|
||
|
|
||
|
function genFresh () {
|
||
|
return crypto.createHmac(hash.toLowerCase(), secret)
|
||
|
}
|
||
|
callback(null, res)
|
||
|
}
|