Skip to content

Commit

Permalink
Merge pull request #20 from itohatweb/few-changes
Browse files Browse the repository at this point in the history
remove: deps.ts & change: don't use Deno enabled workers
  • Loading branch information
JamesBroadberry authored Nov 14, 2021
2 parents 2c1d53b + 887cee3 commit 6461736
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 19 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -29,7 +29,7 @@ import * as bcrypt from "https://deno.land/x/[email protected]/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");
Expand Down
1 change: 0 additions & 1 deletion deps.ts

This file was deleted.

6 changes: 3 additions & 3 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export {
genSalt,
compare,
hash,
genSaltSync,
compareSync,
genSalt,
genSaltSync,
hash,
hashSync,
} from "./src/main.ts";
8 changes: 4 additions & 4 deletions src/bcrypt/bcrypt.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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" : ""),
);

Expand Down Expand Up @@ -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;

Expand Down
12 changes: 6 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,7 +15,7 @@ export async function hash(
): Promise<string> {
let worker = new Worker(
new URL("worker.ts", import.meta.url).toString(),
{ type: "module", deno: true },
{ type: "module" },
);

worker.postMessage({
Expand All @@ -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.
Expand All @@ -47,7 +47,7 @@ export async function genSalt(
): Promise<string> {
let worker = new Worker(
new URL("worker.ts", import.meta.url).toString(),
{ type: "module", deno: true },
{ type: "module" },
);

worker.postMessage({
Expand All @@ -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
Expand All @@ -80,7 +80,7 @@ export async function compare(
): Promise<boolean> {
let worker = new Worker(
new URL("worker.ts", import.meta.url).toString(),
{ type: "module", deno: true },
{ type: "module" },
);

worker.postMessage({
Expand Down
2 changes: 1 addition & 1 deletion test/mod.test.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down

0 comments on commit 6461736

Please sign in to comment.