Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(node/crypto): crypto.timingSafeEqual is not a function #2436

Closed
yeskunall opened this issue Jul 12, 2022 · 4 comments
Closed

(node/crypto): crypto.timingSafeEqual is not a function #2436

yeskunall opened this issue Jul 12, 2022 · 4 comments
Labels
bug Something isn't working needs triage

Comments

@yeskunall
Copy link

Describe the bug

I tried to use timingSafeEqual from Node.js’ Crypto API, expecting it to be available based on #1333, but I get the following error:

Uncaught TypeError: crypto.timingSafeEqual is not a function

Steps to Reproduce

$ deno
> crypto.timingSafeEqual()
Uncaught TypeError: crypto.timingSafeEqual is not a function
    at <anonymous>:2:8

Expected behavior

$ deno
> crypto.timingSafeEqual()
Uncaught:
[TypeError: The "buf1" argument must be an instance of ArrayBuffer, Buffer, TypedArray, or DataView.] {
  code: 'ERR_INVALID_ARG_TYPE'
}

In #2263 the unimplemented methods were stubbed out. However, in the same PR, the implementation for timingSafeEqual was simply moved (node/_crypto/timingSafeEqual.ts → node/internal_binding/_timingSafeEqual.ts), implying it should be available.

Does that mean the function is simply not available in deno_std (stable) yet? Anything (blatantly obvious, even?) I’m missing out? Thanks for the help in advance! 💖

Environment

  • OS: macOS 12.1
  • deno version: v1.23.3
  • std version: v0.147.0
@yeskunall yeskunall added bug Something isn't working needs triage labels Jul 12, 2022
@SimonRask
Copy link
Contributor

I think you forgot to run the REPL in compat mode. I got the following:

$ deno repl --compat --unstable
Deno 1.23.3
exit using ctrl+d or close()
> crypto.timingSafeEqual()
Uncaught TypeError: Cannot read properties of undefined (reading 'byteLength')
    at Object.timingSafeEqual (https://deno.land/std@0.147.0/node/internal_binding/_timingSafeEqual.ts:14:9)
    at <anonymous>:2:8

@kt3k
Copy link
Member

kt3k commented Jul 13, 2022

deno's global crypto is Web Crypto API's crypto. You need to import it from std/node/crypto.ts to use node compatible crypto

import * as crypto from "https://deno.land/std@0.148.0/node/crypto.ts";
console.log(crypto.timingSafeEqual);

@yeskunall
Copy link
Author

Ah, looks I need to RTM better. FWIW, here’s where I should have been looking: Deno Manual > Interoperating with Node and NPM > Node compatibility mode.

I’ll be closing this now. Thank you @SimonRask and @kt3k!

@stefnotch
Copy link

Relevant PR for future readers
#2503

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

4 participants