# hmac-js

> A simple implementation of HMAC hash generation and validation.

Latest version **1.0.8** (published 2019-03-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install hmac-js
pnpm add hmac-js
yarn add hmac-js
bun add hmac-js
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.8 |
| Published | 2019-03-19 |
| First published | 2019-03-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 11.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Mateus Silva |
| Maintainers | mateusilva |

## Links

- npm: https://www.npmjs.com/package/hmac-js
- Repository: https://github.com/maateusilva/hmac-js
- Homepage: https://github.com/maateusilva/hmac-js#readme
- Issues: https://github.com/maateusilva/hmac-js/issues
- npm.io page: https://npm.io/package/hmac-js

## Dependencies (2)

- [crypto](https://npm.io/package/crypto.md) ^1.0.1
- [@types/node](https://npm.io/package/@types/node.md) ^11.11.3

## Recent versions

- 1.0.8 (latest) — 2019-03-19
- 1.0.7 — 2019-03-19
- 1.0.6 — 2019-03-19
- 1.0.5 — 2019-03-19
- 1.0.4 — 2019-03-19
- 1.0.3 — 2019-03-19
- 1.0.2 — 2019-03-19
- 1.0.1 — 2019-03-19
- 1.0.0 — 2019-03-19

## README

# hmac-js
A simple implementation of HMAC token generation and validation.

```sh
npm install hmac-js
```
or
```sh
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.

```js
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.

---
_Source: https://npm.io/package/hmac-js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
