Argon2.ts overview
Argon2id over WebAssembly (the RustCrypto crate built by @thomasfosterau/argon2), compiled once at module scope, so it runs on Node, Bun, Deno and Workers. verify reads the costs from the stored PHC string, so older hashes keep verifying, and refuses one over the verify ceiling before hashing.
Exports Grouped by Category
utils
argon2Hasher
Create an Argon2id Password.PasswordHasher backed by WebAssembly.
Defaults to OWASP’s low-memory profile (m = 19 MiB, t = 2, p = 1) so the hasher is safe to run on Cloudflare Workers; pass serverProfile (or your own numbers) on a plain Node deployment.
verify refuses, with a HashingError and before running the KDF, a stored hash whose costs exceed the verify ceiling (maxMemoryKiB 131072, maxIterations 10, maxParallelism 8 unless configured). Throws a Argon2ConfigError when a limit is not a positive integer, or when the configured costs exceed the ceiling, since their hashes would not verify.
needsRehash is true for a stored hash verify refuses, and for one weaker than the configured costs: another variant (argon2i, argon2d), a lower m, t or p, or a shorter salt or digest. The core’s sign-in flows call it after a successful verify and store a fresh hash, so raising the costs upgrades each user on their next sign-in. A hash at least as strong in every parameter is kept.
Example
import { argon2Hasher, argon2HasherLayer } from "@thomasfosterau/effect-auth-argon2/Argon2"
import { serverProfile } from "@thomasfosterau/effect-auth-argon2/Common"
const hasher = argon2Hasher() // OWASP low-memory defaults
const layer = argon2HasherLayer(serverProfile) // 64 MiB, t = 3 on Node
Signature
declare const argon2Hasher: (options?: Argon2Options) => PasswordHasherService
argon2HasherLayer
A Layer providing Password.PasswordHasher backed by the WASM Argon2id hasher. Use in place of PasswordHasher.layer() to make Argon2id the default hasher for new passwords. Like argon2Hasher, it throws an Argon2ConfigError when the configured costs exceed the verify ceiling.
Signature
declare const argon2HasherLayer: (options?: Argon2Options) => Layer.Layer<Password.PasswordHasher>