bcrypt-ts is a TypeScript-first, pure JavaScript implementation of the bcrypt password-hashing function, designed for both Node.js and browser environments. It provides cryptographic hashing for passwords, focusing on security features like salting and an adaptive iteration count to resist brute-force attacks. The current stable version is 8.0.1. The project appears to have a relatively active release cadence, with major versions (v6, v7, v8) released over time, often driven by Node.js version support or build system changes. Key differentiators from `bcrypt.js` include being fully written in TypeScript, providing separate ESM modules optimized for Node.js and browsers, offering better tree-shaking, and having a minified output. While compatible with the C++ `bcrypt` binding, it's inherently slower due to being a pure JavaScript implementation (approximately 30% slower according to the README, referencing `bcrypt.js` benchmarks), which means fewer iterations can be performed in the same timeframe, requiring careful consideration of the work factor.
npm install bcrypt-tsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to asynchronously generate a salt, hash a password, and then compare a candidate password against the stored hash using `bcrypt-ts`.
Migrate your codebase to use ES module `import` syntax instead of `require()`. Ensure your `package.json` specifies `"type": "module"` or uses `.mjs` file extensions for ESM files. Update your build tools to handle ESM.
Update your Node.js runtime environment to version 20 or newer. Check your `engines` field in `package.json` to ensure compatibility and consider using a Node.js version manager like `nvm`.
No direct fix is typically needed as bcrypt is designed to be backward compatible with different hash versions. However, be aware of this change if you are doing any low-level hash manipulation or validation against specific patterns.
When choosing the work factor (salt rounds), benchmark the hashing time on your production hardware and adjust the rounds downward to achieve your desired target time (e.g., 200-500ms). Do not blindly port work factors from C++ `bcrypt` implementations.
Implement explicit length checks for user passwords *before* passing them to `bcrypt-ts`. Use `Buffer.byteLength(password, 'utf8')` to get the byte length and ensure it's `<= 72`. The library provides a `truncates(password)` utility for this.
Update your project to use ES module `import` syntax: `import { func } from 'bcrypt-ts';`. Ensure your `package.json` has `"type": "module"` or that the file importing `bcrypt-ts` has a `.mjs` extension.Upgrade your Node.js environment to version 20 or newer. You can use a Node.js version manager like `nvm` to switch versions (e.g., `nvm install 20 && nvm use 20`).
Ensure your bundler (webpack, Vite, Rollup) is correctly configured to use the browser-specific bundle of `bcrypt-ts`. If issues persist, manually import from the browser bundle: `import { hash } from 'bcrypt-ts/browser'`.No dependency data recorded yet.