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

Import named 'diffieHellman' not found in module 'crypto' #6782

Open
huseeiin opened this issue Oct 29, 2023 · 9 comments
Open

Import named 'diffieHellman' not found in module 'crypto' #6782

huseeiin opened this issue Oct 29, 2023 · 9 comments
Labels
bug Something isn't working node.js Compatibility with Node.js APIs

Comments

@huseeiin
Copy link
Contributor

What version of Bun is running?

1.0.7

What platform is your computer?

Linux 6.1.0-10-amd64 x86_64 unknown

What steps can reproduce the bug?

use jose in vite as an ssr module

What is the expected behavior?

it works in node

What do you see instead?

SyntaxError: Import named 'diffieHellman' not found in module 'crypto'.
at processTicksAndRejections (:61:39)

Additional information

import {EncryptJWT, jwtDecrypt} from 'jose'

const SECRET = new TextEncoder().encode('SECRET')

const encrypted = await new EncryptJWT({hello: 'world'})
	.setProtectedHeader({
		alg: 'dir',
		enc: 'A128CBC-HS256'
	})
	.setExpirationTime('1h')
	.encrypt(SECRET)

const decrypted = await jwtDecrypt(encrypted, SECRET)

some code to test

@huseeiin huseeiin added the bug Something isn't working label Oct 29, 2023
@SaimonWoidig
Copy link

SaimonWoidig commented Oct 30, 2023

Using jose in Astro SSR (using Vite SSR modules). Bun version is 1.0.7 aswell.

bun -version
1.0.7

bunx --bun astro dev --host
  🚀  astro  v3.4.0 started in 249ms
  
  ┃ Local    http://localhost:4321/
  ┃ Network  http://172.20.128.76:4321/
  
2:36:33 PM [vite] Error when evaluating SSR module /home/swoidig/programming/my-astro-project-using-bun/src/middleware: failed to import "jose"
|- SyntaxError: Import named 'diffieHellman' not found in module 'crypto'.
    at processTicksAndRejections (:61:39)

Also I am only using the jwtVerify method. I think that simply using the module in a Vite SSR module running on Bun causes the error.

@huseeiin
Copy link
Contributor Author

Using jose in Astro SSR (using Vite SSR modules). Bun version is 1.0.7 aswell.

bun -version
1.0.7

bunx --bun astro dev --host
  🚀  astro  v3.4.0 started in 249ms
  
  ┃ Local    http://localhost:4321/
  ┃ Network  http://172.20.128.76:4321/
  
2:36:33 PM [vite] Error when evaluating SSR module /home/swoidig/programming/my-astro-project-using-bun/src/middleware: failed to import "jose"
|- SyntaxError: Import named 'diffieHellman' not found in module 'crypto'.
    at processTicksAndRejections (:61:39)

Also I am only using the jwtVerify method. I think that simply using the module in a Vite SSR module running on Bun causes the error.

nice to see i'm not the only one. i was using sveltekit btw :D

@Electroid Electroid added the needs investigate Needs to be investigated to find the root cause label Oct 30, 2023
@Electroid Electroid changed the title jose error Import named 'diffieHellman' not found in module 'crypto' Oct 30, 2023
@Electroid Electroid added node.js Compatibility with Node.js APIs and removed needs investigate Needs to be investigated to find the root cause labels Oct 30, 2023
@cirospaciari
Copy link
Collaborator

@xxxhussein this is still happening on bun v1.0.11?

now running the test code I got this result:

import { EncryptJWT, jwtDecrypt } from "jose";

const SECRET = new TextEncoder().encode("12345678912345678912345678912345");

const encrypted = await new EncryptJWT({ hello: "world" })
  .setProtectedHeader({
    alg: "dir",
    enc: "A128CBC-HS256",
  })
  .setExpirationTime("1h")
  .encrypt(SECRET);

const decrypted = await jwtDecrypt(encrypted, SECRET);
console.log(decrypted);
{
  payload: {
    hello: "world",
    exp: 1699567220
  },
  protectedHeader: {
    alg: "dir",
    enc: "A128CBC-HS256"
  }
}

@SaimonWoidig
Copy link

@xxxhussein this is still happening on bun v1.0.11?

now running the test code I got this result:

import { EncryptJWT, jwtDecrypt } from "jose";

const SECRET = new TextEncoder().encode("12345678912345678912345678912345");

const encrypted = await new EncryptJWT({ hello: "world" })
  .setProtectedHeader({
    alg: "dir",
    enc: "A128CBC-HS256",
  })
  .setExpirationTime("1h")
  .encrypt(SECRET);

const decrypted = await jwtDecrypt(encrypted, SECRET);
console.log(decrypted);
{
  payload: {
    hello: "world",
    exp: 1699567220
  },
  protectedHeader: {
    alg: "dir",
    enc: "A128CBC-HS256"
  }
}

I have to try it on my own. But since you tried it, I guess it works now. I will try it out as soon as I can.

@huseeiin
Copy link
Contributor Author

@xxxhussein this is still happening on bun v1.0.11?

now running the test code I got this result:

import { EncryptJWT, jwtDecrypt } from "jose";

const SECRET = new TextEncoder().encode("12345678912345678912345678912345");

const encrypted = await new EncryptJWT({ hello: "world" })
  .setProtectedHeader({
    alg: "dir",
    enc: "A128CBC-HS256",
  })
  .setExpirationTime("1h")
  .encrypt(SECRET);

const decrypted = await jwtDecrypt(encrypted, SECRET);
console.log(decrypted);
{
  payload: {
    hello: "world",
    exp: 1699567220
  },
  protectedHeader: {
    alg: "dir",
    enc: "A128CBC-HS256"
  }
}

yes

@huseeiin
Copy link
Contributor Author

it works now. I was on v1.0.11 and upgraded to v1.0.13 so idk if the fix was in v1.0.12 or v1.0.13

@ssebastianoo
Copy link

I'm on SvelteKit using Bun 1.1.12 and I still get SyntaxError: Export named 'diffieHellman' not found in module 'crypto'.
image

@huseeiin
Copy link
Contributor Author

I'm on SvelteKit using Bun 1.1.12 and I still get SyntaxError: Export named 'diffieHellman' not found in module 'crypto'. image

i guess i should reopen

@huseeiin huseeiin reopened this Jun 11, 2024
@birkskyum
Copy link
Collaborator

There is an implementation here in rust - https://crates.io/crates/x25519-dalek don't know if that could be used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working node.js Compatibility with Node.js APIs
Projects
None yet
Development

No branches or pull requests

6 participants