🚀 Big News:Socket Has Acquired Secure Annex.Learn More
Socket
Book a DemoSign in
Socket

tsse

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tsse

Constant time string/buffer equals

latest
Source
npmnpm
Version
2.1.0
Version published
Weekly downloads
9.5K
-21.31%
Maintainers
1
Weekly downloads
 
Created
Source

tsse

Latest version on npm Downloads on npm Project license
Lint status Test macOS status Test Ubuntu status Test Windows status Codecov Coverage report Known Vulnerabilities
XO Code Style used AVA Test Runner used Istanbul Test Coverage used NI Scaffolding System used NP Release System used

⏱ Constant time string/buffer equals.
Coded with ❤️ by Simone Primarosa.

Synopsis

tsse is a string comparison algorithm to prevent Node.js timing attacks.

This differs from crypto.timingSafeEqual because it:

  • supports both strings and Buffers;
  • supports inputs of different lengths.

Install

$ npm install --save tsse

Usage

const tsse = require('tsse');

const hash      = '0a4d55a8d778e5022fab701977c5d840bbc486d0';
const givenHash = '1265a5eb08997ced279d3854629cba68a378b528';

if (tsse(hash, givenHash)) {
  console.log('good hash');
} else {
  console.log('bad hash');
}
// => bad hash

API

tsse(hiddenStr, inputStr) ⇒ boolean

Does a constant-time String comparison.
NOTE: When hiddenStr and inputStr have different lengths hiddenStr is compared to itself, which makes the comparison non-commutative (time-wise).

Kind: global function
Returns: boolean - true if equals, false otherwise.
Access: public

ParamTypeDescription
hiddenStrstring | BufferA string that you don't want to leak.
inputStrstring | BufferAnother string.

Contributing

Contributions are REALLY welcome and if you find a security flaw in this code, PLEASE report it.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the license file for details.

Keywords

tse

FAQs

Package last updated on 05 Jun 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts