mirror of
https://github.com/fluencelabs/js-libp2p-crypto
synced 2025-06-26 05:41:35 +00:00
refactor: the whole thing (#102)
This commit is contained in:
21
src/hmac/index.js
Normal file
21
src/hmac/index.js
Normal file
@ -0,0 +1,21 @@
|
||||
'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)
|
||||
}
|
Reference in New Issue
Block a user