@se-oss/timing-safe-compare
v1.0.0
Published
Constant-time string and buffer comparison for Node.js and browsers.
Maintainers
Readme
@se-oss/timing-safe-compare provides constant-time string and buffer comparison for Node.js and browsers to prevent timing attacks.
📦 Installation
npm install @se-oss/timing-safe-comparepnpm
pnpm install @se-oss/timing-safe-compareyarn
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.
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.
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.
🤝 Contributing
Want to contribute? Awesome! To show your support is to star the project, or to raise issues on GitHub.
Thanks again for your support, it is much appreciated! 🙏
License
MIT © Shahrad Elahi and contributors.
