1.0.8 • Published 5 years ago

hmac-js v1.0.8

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

hmac-js

A simple implementation of HMAC token generation and validation.

npm install hmac-js

or

yarn add hmac-js

Getting Started

This package needs some args:

  • algorithm (string): can be sha256 or sha512;
  • secret (string): your app secret key;
  • payload (string): any data that you want;
  • timestamp (integer): a valid timestamp;

In verifyHash method you can add an extra param, the ttl (hash life time). By default it is 30 seconds.

const Hmac = require('hmac-js');

const timestamp = new Date().getTime();

const hash = Hmac.generateHash({
  algorithm: "sha512",
  secret: "mysecret",
  payload: "mypayload",
  timestamp,
});

const isValidHash = Hmac.verifyHash(hash, {
  algorithm: "sha512",
  secret: "mysecret",
  payload: "mypayload",
  timestamp,
});

if (isValidHash) {
  console.log("This is a valid hash");
} else {
  console.log("This is an invalid hash");
}

That's all folks!

Simple as everything should be.

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago