# tsscmp-js

> Timing safe string compare using double HMA

Latest version **1.0.2** (published 2024-03-23) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2024-03-23 |
| First published | 2024-03-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 0 |
| Unpacked size | 9.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | tonysantana1492 |
| Maintainers | tony.santana |
| Keywords | timing safe string compare, double hmac string compare, safe string compare, hmac |

## Links

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

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 1.0.2 (latest) — 2024-03-23
- 1.0.1 — 2024-03-23
- 1.0.0 — 2024-03-23

## README

# Timing safe string compare using double HMAC

Prevents [timing attacks](http://codahale.com/a-lesson-in-timing-attacks/) using Brad Hill's
[Double HMAC pattern](https://www.nccgroup.trust/us/about-us/newsroom-and-events/blog/2011/february/double-hmac-verification/)
to perform secure string comparison. Double HMAC avoids the timing attacks by blinding the
timing channel using random time per attempt comparison against iterative brute force attacks.

## Install

```
npm install tsscmp-js
```

## Why

To compare secret values like **authentication tokens**, **passwords** or
**capability urls** so that timing information is not
leaked to the attacker.

## Example

```js
import { timingSafeCompare } from "tsscmp-js";

const sessionToken = "5439fd10-e3e0-4926-a239-e95658906718";
const givenToken = "5439fd10-e3e0-4926-a239-e95658906718";

const isValid = await timingSafeCompare(sessionToken, givenToken);

if (isValid) {
  console.log("good token");
} else {
  console.log("bad token");
}
```

## License

[MIT](LICENSE)

**Credits to:** [@suryagh](https://github.com/suryagh)

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