https://github.com/shahradelahi/timing-safe-compare
🔐 Isomorphic constant-time string and buffer comparison to prevent timing attacks.
https://github.com/shahradelahi/timing-safe-compare
browser constant-time cryptography isomorphic nodejs security timing-attack
Last synced: 2 months ago
JSON representation
🔐 Isomorphic constant-time string and buffer comparison to prevent timing attacks.
- Host: GitHub
- URL: https://github.com/shahradelahi/timing-safe-compare
- Owner: shahradelahi
- License: mit
- Created: 2026-02-08T00:23:49.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2026-03-17T13:26:39.000Z (3 months ago)
- Last Synced: 2026-03-25T18:11:04.969Z (2 months ago)
- Topics: browser, constant-time, cryptography, isomorphic, nodejs, security, timing-attack
- Language: TypeScript
- Homepage: https://npmjs.com/@se-oss/timing-safe-compare
- Size: 101 KB
- Stars: 2
- Watchers: 0
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
timing-safe-compare
_@se-oss/timing-safe-compare_ provides constant-time string and buffer comparison for Node.js and browsers to prevent timing attacks.
---
- [Installation](#-installation)
- [Usage](#-usage)
- [Documentation](#-documentation)
- [Contributing](#-contributing)
- [License](#license)
## 📦 Installation
```bash
npm install @se-oss/timing-safe-compare
```
Install using your favorite package manager
**pnpm**
```bash
pnpm install @se-oss/timing-safe-compare
```
**yarn**
```bash
yarn add @se-oss/timing-safe-compare
```
## 📖 Usage
### String Comparison
Compare two strings in constant time. This is useful for comparing passwords, tokens, or any other sensitive data where the length is already known or handled.
```ts
import { safeCompare } from '@se-oss/timing-safe-compare';
if (safeCompare(inputPassword, storedPassword)) {
// Passwords match
}
```
### Buffer Comparison
Compare two `Uint8Array` (or `Buffer` in Node.js) instances in constant time. Note that both buffers must have the same length.
```ts
import { timingSafeEqual } from '@se-oss/timing-safe-compare';
const a = new Uint8Array([1, 2, 3]);
const b = new Uint8Array([1, 2, 3]);
if (timingSafeEqual(a, b)) {
// Buffers are equal
}
```
## 📚 Documentation
For all configuration options, please see [the API docs](https://www.jsdocs.io/package/@se-oss/timing-safe-compare).
## 🤝 Contributing
Want to contribute? Awesome! To show your support is to star the project, or to raise issues on [GitHub](https://github.com/shahradelahi/timing-safe-compare).
Thanks again for your support, it is much appreciated! 🙏
## License
[MIT](/LICENSE) © [Shahrad Elahi](https://github.com/shahradelahi) and [contributors](https://github.com/shahradelahi/timing-safe-compare/graphs/contributors).