Code Monkey home page Code Monkey logo

deno-bcrypt's People

Contributors

bidek56 avatar itohatweb avatar jamesbroadberry avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

deno-bcrypt's Issues

Version Std Encoding Import

It would be nice if you could version the following import on bcrypt/bcrypt.ts:

import { encode } from "https://deno.land/std/encoding/utf8.ts";

To avoid using the master branch and causing any issues for users (should any ever arise)

Error just importing

I just import the module and it throw me this error:

error: TS2345 [ERROR]: Argument of type '{ type: "module"; deno: boolean; }' is not assignable to parameter of type 'WorkerOptions'.
  Object literal may only specify known properties, and 'deno' does not exist in type 'WorkerOptions'.
    { type: "module", deno: true },

compareSync function breaks with deno v1.23.0

Hi togehter,

I am using the compareSync functions to verify a password with a password hash and it is deployed to Deno Deploy. Since I would like to update to deno v1.23.0 the function just returns "false" for the same input which returns "true" on deno v1.22.3. Funnily the compare function (without "Sync") works on Deno v1.23.0 but this doesn't work on Deno Deploy (as described in another issue).

Has anybody a solution for that? Does deno v1.23.0 or std v0.144.0 breaks the library?

Looking forward to a solution.

Kind regards

Leo

deno-bcrypt leads to Uncaught (in promise) Error:Unhandled error event reached main worker

I introduced deno-bcrypt into an application I am building, as soon as I do, I start getting this error:

error: Uncaught (in worker "") TS2304 [ERROR]: Cannot find name 'window'.
  let binaryString = window.atob(b);
                     ~~~~~~
    at https://deno.land/x/[email protected]/src/helper.ts:60:22
error: Uncaught (in promise) Error: Unhandled error event reached main worker.
    at Worker.#poll (deno:runtime/js/11_workers.js:269:21)

This error starts popping up on just adding the dependencies without even using it.

export {create} from "https://deno.land/x/[email protected]/mod.ts";

Any ideas on how to debug this? Not sure if it matters, but my application has some logic that already uses workers

Argument of type '{ type: "module"; deno: boolean; }' is not assignable to parameter of type 'WorkerOptions'

error: TS2345 [ERROR]: Argument of type '{ type: "module"; deno: boolean; }' is not assignable to parameter of type 'WorkerOptions'.
Object literal may only specify known properties, and 'deno' does not exist in type 'WorkerOptions'.
{ type: "module", deno: true },
~~~~~~~~~~
at https://deno.land/x/[email protected]/src/main.ts:18:23

TS2345 [ERROR]: Argument of type '{ type: "module"; deno: boolean; }' is not assignable to parameter of type 'WorkerOptions'.
Object literal may only specify known properties, and 'deno' does not exist in type 'WorkerOptions'.
{ type: "module", deno: true },
~~~~~~~~~~
at https://deno.land/x/[email protected]/src/main.ts:50:23

TS2345 [ERROR]: Argument of type '{ type: "module"; deno: boolean; }' is not assignable to parameter of type 'WorkerOptions'.
Object literal may only specify known properties, and 'deno' does not exist in type 'WorkerOptions'.
{ type: "module", deno: true },
~~~~~~~~~~
at https://deno.land/x/[email protected]/src/main.ts:83:23

bcrypt is broken on canary version of deno

Use deno upgrade --canary and the bcrypt.compare(pw, hashed_pw) function no longer works on accounts created before upgrading. Accounts created using canary DO work.

If you downgrade back to 1.22 deno upgrade (remove --canary flag) older accounts can now login but newer accoutns created on --canary can NOT login anymore.

TS Compiler Issues

Getting TypeScript compiler issues when running a Deno app that imports bcrypt. I can work on a PR if you don't have the time

Also I'm not sure what Deno version you are using but i think they information should be added to the README, i'm currently running Deno v1.0.1 but seems like it would error regardless of version due to missing types

Is there also a specific version we can import instead of the master branch each time?

error TS2339: Property 'crypto' does not exist on type 'typeof globalThis'.
► https://deno.land/x/bcrypt/bcrypt/bcrypt.ts:4:33
     let crypto: Crypto = globalThis.crypto;

error TS2345: Argument of type '{ type: "module"; deno: boolean; }' is not assignable to parameter of type '{ type?: "classic" | "module" | undefined; name?: string | undefined; }'.
Object literal may only specify known properties, and 'deno' does not exist in type '{ type?: "classic" | "module" | undefined; name?: string | undefined; }'.
► https://deno.land/x/bcrypt/main.ts:18:23
     { type: "module", deno: true },

error TS7006: Parameter 'event' implicitly has an 'any' type.
► https://deno.land/x/bcrypt/main.ts:30:25
worker.onmessage = (event) => {

error TS2345: Argument of type '{ type: "module"; deno: boolean; }' is not assignable to parameter of type '{ type?: "classic" | "module" | undefined; name?: string | undefined; }'.
Object literal may only specify known properties, and 'deno' does not exist in type '{ type?: "classic" | "module" | undefined; name?: string | undefined; }'.
► https://deno.land/x/bcrypt/main.ts:50:23
{ type: "module", deno: true },

error TS7006: Parameter 'event' implicitly has an 'any' type.
► https://deno.land/x/bcrypt/main.ts:61:25
worker.onmessage = (event) => {

error TS2345: Argument of type '{ type: "module"; deno: boolean; }' is not assignable to parameter of type '{ type?: "classic" | "module" | undefined; name?: string | undefined; }'.
Object literal may only specify known properties, and 'deno' does not exist in type '{ type?: "classic" | "module" | undefined; name?: string | undefined; }'.
► https://deno.land/x/bcrypt/main.ts:83:23
{ type: "module", deno: true },

error TS7006: Parameter 'event' implicitly has an 'any' type.
► https://deno.land/x/bcrypt/main.ts:95:25
worker.onmessage = (event) => {

Argument of type 'string' is not assignable to parameter of type 'number | undefined'

hi, I was trying this library but I am getting this error. how can I solve this?

error: TS2345 [ERROR]: Argument of type 'string' is not assignable to parameter of type 'number | undefined'.
const hash = await bcrypt.hash("test", salt);

import * as bcrypt from "https://deno.land/x/bcrypt/mod.ts";

const salt = await bcrypt.genSalt(8);
const hash = await bcrypt.hash("test", salt);

console.log(hash);

TypeError: bcrypt.hashSync is not a function

I'm getting this error and I cannot understand what's wrong.
I've tried also to work with the async version, but I'm getting the same error.

    at Object.hashIt (hash.ts:4:19)
    at store (UserController.ts:29:26)
    at async dispatch (middleware.ts:41:7)
    at async dispatch (middleware.ts:41:7)
    at async dispatch (middleware.ts:41:7)
    at async Application.#handleRequest (application.ts:252:9)``

Argument of type '{ type: "module"; deno: boolean; }' is not assignable to parameter of type 'WorkerOptions'.

I am using deno Version 1.11.1

import * as bcrypt from "https://deno.land/x/[email protected]/mod.ts";
After importing bcrypt, as above , I get these errors :-

error: TS2345 [ERROR]: Argument of type '{ type: "module"; deno: boolean; }' is not assignable to parameter of type 'WorkerOptions'.
Object literal may only specify known properties, and 'deno' does not exist in type 'WorkerOptions'.
{ type: "module", deno: true },
~~~~~~~~~~
at https://deno.land/x/[email protected]/src/main.ts:18:23

TS2345 [ERROR]: Argument of type '{ type: "module"; deno: boolean; }' is not assignable to parameter of type 'WorkerOptions'.
Object literal may only specify known properties, and 'deno' does not exist in type 'WorkerOptions'.
{ type: "module", deno: true },
~~~~~~~~~~
at https://deno.land/x/[email protected]/src/main.ts:50:23

TS2345 [ERROR]: Argument of type '{ type: "module"; deno: boolean; }' is not assignable to parameter of type 'WorkerOptions'.
Object literal may only specify known properties, and 'deno' does not exist in type 'WorkerOptions'.
{ type: "module", deno: true },
~~~~~~~~~~
at https://deno.land/x/[email protected]/src/main.ts:83:23

Found 3 errors.
[E] [daem] app crashed - waiting for file changes before starting ...

Failed in Deployment

i tried to import the bcrypt like import * as bcrypt from "https://deno.land/x/bcrypt/mod.ts"; instead of giving me functions like genSalt and hash it gave me hashpw and gensalt , however it worked passwords are hashed but when i tried to upload project on heroku with all permissions it paniced.

Error:
error: Uncaught Error: Cannot find module "https://deno.land/x/[email protected]/src/worker.ts" in cache, --cached-only is specified

which caused abnormal termination of whole project

Async Worker without --allow-net=deno.land

Im working with Async bcrypt but always need the --allow-net option with "deno.land" even when i save in cache the dependencies (explicitly i run deno cache --unstable https://deno.land/x/[email protected]/src/worker.ts previously trying to force the cache)

Have some option to avoid the call to "deno.land" in execution time and use the cache? Or i'm missing something?

I think in:

  • Apps without internet access
  • Developments where can't use "deno.land" in --allow-net option by security reasons in execution time
  • Because 'deno.land' will be down at these time.

Thanks for your support!

Subresource check failed using lock

Hello,

Thanks for this lib but I'm currently facing with an issue. I'm using lock.json feature from Deno to check package integrity. But when I used a function from Bcrypt package (like bcrypt.hash()) the following issue is printed : Subresource integrity check failed --lock=lock.json https://deno.land/x/bcrypt/worker.ts and the server is down 😞

Info :
OS: MacOS v10.15.5
Deno: 1.1.1
deno-bcrypt: 6ed1ba413208fa23109f5055fc58eb5f62fc6cee863142b66e7b90be3f8bab4b
Command executed : deno run --allow-net --allow-env --allow-read --allow-write --allow-plugin --lock lock.json --inspect=127.0.0.1:9229 --unstable index.ts

How to run with lock file and cached only?

The worker imports differ the import signatures of the file making it impossible to run with deno run --lock=lock.json --cached-only. Is there a way this could be supported somehow?

Import fails in Deno v1.7.x

Version Info:

deno 1.7.4 (release, x86_64-pc-windows-msvc)
v8 9.0.123
typescript 4.1.4

I tried importing the module in Deno v1.7.3/v1.7.4 but I get this error.

> const bcrypt = await import("https://deno.land/x/[email protected]/mod.ts")
Check https://deno.land/x/[email protected]/mod.ts
Uncaught TypeError: TS2345 [ERROR]: Argument of type '{ type: "module"; deno: boolean; }' is not assignable to parameter of type 'WorkerOptions'.
  Object literal may only specify known properties, and 'deno' does not exist in type 'WorkerOptions'.
    { type: "module", deno: true },
                      ~~~~~~~~~~
    at https://deno.land/x/[email protected]/src/main.ts:18:23

TS2345 [ERROR]: Argument of type '{ type: "module"; deno: boolean; }' is not assignable to parameter of type 'WorkerOptions'.
  Object literal may only specify known properties, and 'deno' does not exist in type 'WorkerOptions'.
    { type: "module", deno: true },
                      ~~~~~~~~~~
    at https://deno.land/x/[email protected]/src/main.ts:50:23

TS2345 [ERROR]: Argument of type '{ type: "module"; deno: boolean; }' is not assignable to parameter of type 'WorkerOptions'.
  Object literal may only specify known properties, and 'deno' does not exist in type 'WorkerOptions'.
    { type: "module", deno: true },
                      ~~~~~~~~~~
    at https://deno.land/x/[email protected]/src/main.ts:83:23

This also occurs when importing into a module and not only in the Deno REPL.

Maybe you can look into it thanks!

Add test to catch #27 in the future

Release 0.4.0 does not contain a test for #27 to catch a possible regression in the future. I wrote a test for my project but would prefer if you could add it to the deno-bcrypt project (or pass it on to the Deno project if more applicable). The idea is to manually generate a hash once and assert that await compare(plaintext, oldHash) still returns true in newly released versions of Deno and bcrypt. If you run the test with Deno 1.22.3 it correctly passes, if you run it with Deno 1.23.0 it correctly fails as it detects the bug.

// test.ts
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
import { compare } from "https://deno.land/x/[email protected]/mod.ts";

Deno.test(compare.name, async () => {
  // Assert that hash generated with older Deno and bcrypt version is still 
  // recognized as valid by newer versions of Deno and bcrypt
  assertEquals(
    await compare(
      "password123",
      "$2a$10$i7yVylH68UTYSoa./.BWxO0NTXjvPRMzT6F0CgKItqKUqwQwj3y0W",
    ),
    true,
  );
});

Error when importing

When I tried to import the package, 3 errors appeared in my terminal:-

I used this line to import:-
import * as bcrypt from "https://deno.land/x/[email protected]/mod.ts";

My deno version: 1.9.0

I'm using Windows 10 as my operating system

error: TS2345 [ERROR]: Argument of type '{ type: "module"; deno: boolean; }' is not assignable to parameter of type 'WorkerOptions'.
Object literal may only specify known properties, and 'deno' does not exist in type 'WorkerOptions'.
{ type: "module", deno: true },
~~~~~~~~~~
at https://deno.land/x/[email protected]/src/main.ts:18:23

TS2345 [ERROR]: Argument of type '{ type: "module"; deno: boolean; }' is not assignable to parameter of type 'WorkerOptions'.
Object literal may only specify known properties, and 'deno' does not exist in type 'WorkerOptions'.
{ type: "module", deno: true },
~~~~~~~~~~
at https://deno.land/x/[email protected]/src/main.ts:50:23

TS2345 [ERROR]: Argument of type '{ type: "module"; deno: boolean; }' is not assignable to parameter of type 'WorkerOptions'.
Object literal may only specify known properties, and 'deno' does not exist in type 'WorkerOptions'.
{ type: "module", deno: true },
~~~~~~~~~~
at https://deno.land/x/[email protected]/src/main.ts:83:23

Found 3 errors.
[E] [daem] app crashed - waiting for file changes before starting ...

Deno Deploy Support

Currently hash and compare are not supported when deploying code on Deno Deploy. This is due to Worker not being defined refer to upstream issue.

However, until Worker is implemented with Deno Deploy you can use the hashSync and compareSync methods.

I have included a helper below which allows for easily switching between these two methods for anyone working on a codebase designed to run efficiently locally and inside Deno Deploy.

import {
  hash as hashPromise,
  hashSync,
  compare as comparePromise,
  compareSync,
} from "https://deno.land/x/bcrypt/mod.ts";

export const isRunningInDenoDeploy = Deno.permissions?.query === undefined; // This is crude check for if the code in running in Deno Deploy. It works for now but may not work in the future.

export const hash: typeof hashPromise = isRunningInDenoDeploy
  ? (plaintext: string, salt: string | undefined = undefined) =>
      new Promise((res) => res(hashSync(plaintext, salt)))
  : hashPromise;
export const compare: typeof comparePromise = isRunningInDenoDeploy
  ? (plaintext: string, hash: string) =>
      new Promise((res) => res(compareSync(plaintext, hash)))
  : comparePromise;

I primarily created this issue to help anyone who runs into the same issue. It would be cool to see the helpers I included added to this library but I think this would be unlikely given how hacky it is.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.