diff --git a/README.md b/README.md index d311765..9b3ce5b 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ The library can be installed as a CLI tool via `deno install`. --allow-plugin \ --allow-net \ --unstable \ - argon2 https://deno.land/x/argon2/cli/mod.ts + argon2 https://deno.land/x/argon2/cli/argon2 ``` diff --git a/cli/mod.ts b/cli/argon2 similarity index 100% rename from cli/mod.ts rename to cli/argon2 diff --git a/cli/commands/hash.ts b/cli/commands/hash.ts index f4a964c..d13dbf2 100755 --- a/cli/commands/hash.ts +++ b/cli/commands/hash.ts @@ -58,15 +58,17 @@ export let hash = new Command() .action(async (options) => { let password = await readStdin(); - console.log(await argon2.hash(password, { - salt: options.salt ? encode(options.salt) : undefined, - secret: options.secret ? encode(options.secret) : undefined, - memoryCost: options.memoryCost ? options.memoryCost : undefined, - timeCost: options.timeCost ? options.timeCost : undefined, - lanes: options.lanes ? options.lanes : undefined, - threadMode: "threadMode" in options ? options.threadMode : undefined, - variant: options.variant ? options.variant : undefined, - data: options.data ? options.data : undefined, - hashLength: options.hashLength ? options.hashLength : undefined, - })); + console.log( + await argon2.hash(password, { + salt: options.salt ? encode(options.salt) : undefined, + secret: options.secret ? encode(options.secret) : undefined, + memoryCost: options.memoryCost ? options.memoryCost : undefined, + timeCost: options.timeCost ? options.timeCost : undefined, + lanes: options.lanes ? options.lanes : undefined, + threadMode: "threadMode" in options ? options.threadMode : undefined, + variant: options.variant ? options.variant : undefined, + data: options.data ? options.data : undefined, + hashLength: options.hashLength ? options.hashLength : undefined, + }), + ); }); diff --git a/examples/hash-with-options.ts b/examples/hash-with-options.ts index cf997c6..04e60cc 100644 --- a/examples/hash-with-options.ts +++ b/examples/hash-with-options.ts @@ -7,18 +7,20 @@ let salt = crypto.getRandomValues( let secret = encode("my-super-secret"); -console.log(await hash("test", { - salt, - secret, - variant: Variant.Argon2id, - version: Version.V13, - memoryCost: 8192, - timeCost: 10, - threadMode: ThreadMode.Parallel, - lanes: 4, - hashLength: 32, - data: { - hashedAt: Date.now(), - requestId: "a00d22c0-4681-4351-8c8f-6f02a42dd941", - }, -})); +console.log( + await hash("test", { + salt, + secret, + variant: Variant.Argon2id, + version: Version.V13, + memoryCost: 8192, + timeCost: 10, + threadMode: ThreadMode.Parallel, + lanes: 4, + hashLength: 32, + data: { + hashedAt: Date.now(), + requestId: "a00d22c0-4681-4351-8c8f-6f02a42dd941", + }, + }), +); diff --git a/lib/common.ts b/lib/common.ts index 42f871b..3f5a473 100644 --- a/lib/common.ts +++ b/lib/common.ts @@ -30,5 +30,5 @@ export interface HashOptions { } export function version() { - return "0.5.2"; + return "0.6.0"; } diff --git a/lib/internal.ts b/lib/internal.ts index 7c7db4a..d069af8 100644 --- a/lib/internal.ts +++ b/lib/internal.ts @@ -57,7 +57,7 @@ export async function installPlugin( await preparing; //@ts-ignore - const { hash } = Deno.core.ops(); + let { argon2_hash } = Deno.core.ops(); if (typeof password !== "string") { throw new Argon2Error( @@ -66,13 +66,11 @@ export async function installPlugin( ); } - let salt = options.salt - ? options.salt - : crypto.getRandomValues( - new Uint8Array( - Math.max(Math.round(Math.random() * 32), MIN_SALT_SIZE), - ), - ); + let salt = options.salt ? options.salt : crypto.getRandomValues( + new Uint8Array( + Math.max(Math.round(Math.random() * 32), MIN_SALT_SIZE), + ), + ); if (salt.length < MIN_SALT_SIZE) { throw new Argon2Error( @@ -95,7 +93,7 @@ export async function installPlugin( let buf = new Uint8Array(1); //@ts-ignore - let result = Deno.core.dispatch(hash, args, buf)!; + let result = Deno.core.dispatch(argon2_hash, args, buf)!; if (buf[0] !== 1) { throw new Argon2Error( @@ -114,13 +112,13 @@ export async function installPlugin( await preparing; //@ts-ignore - const { verify } = Deno.core.ops(); + let { argon2_verify } = Deno.core.ops(); let args = encode(JSON.stringify({ password, hash })); let buf = new Uint8Array(100); //@ts-ignore - let result = Deno.core.dispatch(verify, args, buf)!; + let result = Deno.core.dispatch(argon2_verify, args, buf)!; if (buf[0] !== 1) { throw new Argon2Error( diff --git a/lib/testing.ts b/lib/testing.ts index 23a5f5c..b38b4cb 100644 --- a/lib/testing.ts +++ b/lib/testing.ts @@ -14,25 +14,15 @@ export function assertArgon2Encoded( password: string, options: Partial = {}, ): asserts password { - let variant = options.variant - ? options.variant - : "argon2(i|d|id)"; + let variant = options.variant ? options.variant : "argon2(i|d|id)"; - let version = options.version - ? options.version - : "(16|19)"; + let version = options.version ? options.version : "(16|19)"; - let memoryCost = options.memoryCost - ? options.memoryCost - : "([0-9])+"; + let memoryCost = options.memoryCost ? options.memoryCost : "([0-9])+"; - let timeCost = options.timeCost - ? options.timeCost - : "([0-9])+"; + let timeCost = options.timeCost ? options.timeCost : "([0-9])+"; - let lanes = options.lanes - ? options.lanes - : "([0-9])+"; + let lanes = options.lanes ? options.lanes : "([0-9])+"; let rx = new RegExp( `^\\$${variant}\\$v=${version}\\$m=${memoryCost},t=${timeCost},p=${lanes}\\$.+$`, diff --git a/native/lib.rs b/native/lib.rs index 15d6a56..d1ce4b8 100644 --- a/native/lib.rs +++ b/native/lib.rs @@ -8,6 +8,6 @@ use deno_core::plugin_api::Interface; #[no_mangle] fn deno_plugin_init(context: &mut dyn Interface) { - context.register_op("hash", command::hash); - context.register_op("verify", command::verify); + context.register_op("argon2_hash", command::hash); + context.register_op("argon2_verify", command::verify); } diff --git a/tests/cli.ts b/tests/cli.ts deleted file mode 100755 index 522c186..0000000 --- a/tests/cli.ts +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env -S deno --allow-env --allow-run --allow-read --allow-write --allow-net --allow-plugin --unstable - -import "../cli/mod.ts"; diff --git a/tests/run.ts b/tests/run.ts index bf3608b..a448f39 100644 --- a/tests/run.ts +++ b/tests/run.ts @@ -1,5 +1,5 @@ -import "./lib.test.ts" -import "./testing.test.ts" +import "./lib.test.ts"; +import "./testing.test.ts"; // @ts-ignore -Deno[Deno.internal].runTests() +Deno[Deno.internal].runTests();