@nhz.io/hmac-sha1
Version:
[![Travis Build][travis]](https://travis-ci.org/nhz-io/nhz-io-hmac-sha1) [![NPM Version][npm]](https://www.npmjs.com/package/@nhz.io/hmac-sha1)
30 lines (25 loc) • 558 B
JavaScript
// # HMAC-SHA1 digest
var crypto, digest, hmacSha1;
crypto = require('crypto');
// Curry `secret` to allow reuse
hmacSha1 = function(secret) {
return function(message) {
var hmac;
hmac = crypto.createHmac('sha1', secret);
hmac.update(message, 'utf8');
return hmac.digest('hex');
};
};
digest = function(secret, message) {
var hmac;
// Start curried
hmac = hmacSha1(secret);
// Complete invocation if possible
if (message) {
return hmac(message);
} else {
return hmac;
}
};
// ## Exports
module.exports = digest;