Argon2 for Deno
Argon2 encryption library for Deno.
It uses rust-argon2 under the hood.
API
hash(password: string, options?: HashOptions): Promise<string>
verify(hash: string, password: string): Promise<boolean>
Error handling
In case of 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/lib/mod.ts";
let hash = await hash("test");
assert(await verify(hash, "test"));
Testing
import { Variant } from "https://deno.land/x/argon2/lib/mod.ts";
import { assertArgon2Encoded } from "https://deno.land/x/argon2/lib/testing.ts";
Deno.test("User#password should be an argon2id variant password", async () => {
assertArgon2Encoded(user.password, {
variant: Variant.Argon2id
});
});
CLI
It is possible to install deno-argon2 as a CLI tool insatiable via deno install
.
Installation snippet
deno install \
--allow-env \
--allow-run \
--allow-read \
--allow-write \
--allow-plugin \
--allow-net \
argon2 https://deno.land/x/argon2/cli/mod.ts
After install run --help
to inspect all possible commands.
Permissions
This library automatically download the static library and initialize Deno plugin via plugin_prepare and it requires --allow-read .deno_plugins
, --allow-write .deno_plugins
and --allow-plugin
to be specified.
deno \
--allow-read .deno_plugins \
--allow-write .deno_plugins \
--allow-net
--allow-plugin \
lib/mod.ts
Examples
In the examples/
folder there you can find some usage examples.
To run examples you must
--allow-run
since 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
βββ benches/ # TypeScript benchmarks
βββ examples/ # Development examples