Argon2 for Deno
This repository is a continuation of fdionisi/deno-argon2 which was no longer actively maintained.
Argon2 hashing library for Deno. It uses rust-argon2 via Deno FFI which requires Deno v1.30.0 or higher.
Benchmarks
Benchmark measures performance against x/bcrypt.
See benchmarks/ folder for more details.
- hash
1.02x faster than bcrypt hash - hash with random salt
10.24x faster than bcrypt hash with random salt - verify
2x faster than bcrypt verify
Benchmarks are run on a MacBook Pro (16-inch, 2019) with 2.6 GHz Hexa-Core Intel i7-9750H and 16 GB 2666 MHz DDR4.
API
hash(password: string, options?: HashOptions): Promise<string>
verify(hash: string, password: string): Promise<boolean>Error handling
In case of an error, all methods of this library will throw an
Argon2Error type.
Usage
Library
import { assert } from "https://deno.land/std/testing/asserts.ts";
import { hash, verify } from "https://deno.land/x/argon2_ffi/lib/mod.ts";
const hash = await hash("test");
assert(await verify(hash, "test"));Testing
import { Variant } from "https://deno.land/x/argon2_ffi/lib/mod.ts";
import { assertArgon2Encoded } from "https://deno.land/x/argon2_ffi/lib/testing.ts";
Deno.test("User#password should be an argon2id variant password", async () => {
assertArgon2Encoded(user.password, {
variant: Variant.Argon2id,
});
});CLI
The library can be installed as a CLI tool via deno install.
Installation snippet
```sh
deno install \
-A \
--unstable \
argon2 https://deno.land/x/argon2_ffi/cli/argon2.ts
```After install run --help to inspect all possible commands.
Permissions
The library automatically downloads the static library. It requires
--allow-read, --allow-write, --allow-net and --allow-ffi.
```sh
deno \
--allow-read \
--allow-write \
--allow-net \
--allow-ffi \
--unstable \
lib/mod.ts
```Examples
In the examples/ folder there you can find some usage examples.
To run examples you must
--allow-runsince dev environment builds and initialize the Rust crate.
Available examples
Contributing
Project structure
deno-argon2
βββ lib/ # Core library
βββ native/ # Native glue code
βββ cli/ # CLI wrapper
βββ tests/ # TypeScript tests
βββ benchmarks/ # TypeScript benchmarks
βββ examples/ # Development examples