diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8b73796..ae255e2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - deno: ["v1.2.0", "v1.x"] + deno: ["v1.9.0", "v1.x"] name: Test run with Deno ${{ matrix.deno }} on ${{ matrix.os }} steps: - uses: actions/checkout@master @@ -22,7 +22,7 @@ jobs: run: deno --version - name: Check format - run: deno fmt --check + run: deno fmt --check --ignore=./README.md - name: Run tests run: deno test --unstable --allow-read diff --git a/README.md b/README.md index 5205971..9732de3 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ This is a port from [jBCrypt](https://github.com/jeremyh/jBCrypt) to TypeScript It has zero third-party dependencies. Running in sync requires no permissions. -Running in async functionality requires --allow-net and --unstable +Running in async functionality requires --allow-net ## Import @@ -29,7 +29,7 @@ import * as bcrypt from "https://deno.land/x/bcrypt@v0.2.4/mod.ts"; ### Async -The Async implementation requires WebWorkers which require --allow-net to import Deno standard modules from inside the Worker. Also, to [allow Crypto inside a WebWorker](https://github.com/denoland/deno/pull/5121), you'll need to use the --unstable flag too. +The Async implementation requires WebWorkers which require --allow-net to import Deno standard modules from inside the Worker. ```ts const hash = await bcrypt.hash("test"); diff --git a/deps.ts b/deps.ts deleted file mode 100644 index 823d641..0000000 --- a/deps.ts +++ /dev/null @@ -1 +0,0 @@ -export { encode } from "https://deno.land/std@0.61.0/encoding/utf8.ts"; diff --git a/mod.ts b/mod.ts index 716e44f..dc6a702 100644 --- a/mod.ts +++ b/mod.ts @@ -1,8 +1,8 @@ export { - genSalt, compare, - hash, - genSaltSync, compareSync, + genSalt, + genSaltSync, + hash, hashSync, } from "./src/main.ts"; diff --git a/src/bcrypt/bcrypt.ts b/src/bcrypt/bcrypt.ts index 7d5d4ec..4a7276a 100644 --- a/src/bcrypt/bcrypt.ts +++ b/src/bcrypt/bcrypt.ts @@ -1,7 +1,7 @@ -import { encode } from "../../deps.ts"; import * as base64 from "./base64.ts"; let crypto: Crypto = globalThis.crypto; +const encoder = new TextEncoder(); // BCrypt parameters const GENSALT_DEFAULT_LOG2_ROUNDS = 10; @@ -1238,7 +1238,7 @@ export function hashpw(password: string, salt: string = gensalt()): string { real_salt = salt.substring(off + 3, off + 25); - passwordb = encode( + passwordb = encoder.encode( password + (minor.charCodeAt(0) >= "a".charCodeAt(0) ? "\u0000" : ""), ); @@ -1282,8 +1282,8 @@ export function checkpw(plaintext: string, hashed: string): boolean { let try_bytes: Uint8Array; let try_pw = hashpw(plaintext, hashed); - hashed_bytes = encode(hashed); - try_bytes = encode(try_pw); + hashed_bytes = encoder.encode(hashed); + try_bytes = encoder.encode(try_pw); if (hashed_bytes.length !== try_bytes.length) return false; diff --git a/src/main.ts b/src/main.ts index 9827bf3..5837d25 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,7 +2,7 @@ import * as bcrypt from "./bcrypt/bcrypt.ts"; /** * Generate a hash for the plaintext password - * Requires --allow-net and --unstable flags + * Requires the --allow-net flag * * @export * @param {string} plaintext The password to hash @@ -15,7 +15,7 @@ export async function hash( ): Promise { let worker = new Worker( new URL("worker.ts", import.meta.url).toString(), - { type: "module", deno: true }, + { type: "module" }, ); worker.postMessage({ @@ -36,7 +36,7 @@ export async function hash( /** * Generates a salt using a number of log rounds - * Requires --allow-net and --unstable flags + * Requires the --allow-net flag * * @export * @param {(number | undefined)} [log_rounds=undefined] Number of log rounds to use. Recommended to leave this undefined. @@ -47,7 +47,7 @@ export async function genSalt( ): Promise { let worker = new Worker( new URL("worker.ts", import.meta.url).toString(), - { type: "module", deno: true }, + { type: "module" }, ); worker.postMessage({ @@ -67,7 +67,7 @@ export async function genSalt( /** * Check if a plaintext password matches a hash - * Requires --allow-net and --unstable flags + * Requires the --allow-net flag * * @export * @param {string} plaintext The plaintext password to check @@ -80,7 +80,7 @@ export async function compare( ): Promise { let worker = new Worker( new URL("worker.ts", import.meta.url).toString(), - { type: "module", deno: true }, + { type: "module" }, ); worker.postMessage({ diff --git a/test/mod.test.ts b/test/mod.test.ts index ef0806b..da67734 100644 --- a/test/mod.test.ts +++ b/test/mod.test.ts @@ -1,7 +1,7 @@ import { assertEquals, assertThrows, -} from "https://deno.land/std/testing/asserts.ts"; +} from "https://deno.land/std@0.97.0/testing/asserts.ts"; import * as bcrypt from "../mod.ts";