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

window.crypto is undefined #1612

Open
herodrigues opened this issue Sep 25, 2016 · 6 comments

Comments

Projects
None yet
6 participants
@herodrigues
Copy link

commented Sep 25, 2016

i'm trying to run tests using jsdom and mocha but I got this error:

ReferenceError: crypto is not defined

Is crypto really defined in jsdom?

@domenic

This comment has been minimized.

Copy link
Member

commented Sep 25, 2016

Web Crypto is not implemented in jsdom, that is correct. Pull request welcome!

@domenic domenic added the feature label Sep 25, 2016

@herodrigues

This comment has been minimized.

Copy link
Author

commented Sep 25, 2016

Thanks @domenic 👍

@koresar

This comment has been minimized.

Copy link

commented Jul 2, 2018

I've just proposed to use https://github.com/anvilresearch/webcrypto to implement window.crypto.

See PR #2283

If someone can poke the (right) maintainer I'd be very thankful.

@Falieson

This comment has been minimized.

Copy link

commented Jul 30, 2018

I just added the following to my jest.setup.js

crypto = require('@trust/webcrypto')
@ernaneluis

This comment has been minimized.

Copy link

commented Sep 8, 2018

this works for now

@nealeu

This comment has been minimized.

Copy link

commented Jan 14, 2019

If you only require random numbers to be polyfilled, then you can also do

var nodeCrypto = require('crypto');
global.crypto = {
    getRandomValues: function(buffer: T) { return nodeCrypto.randomFillSync(buffer);}
};

Note: You'll need Node v10 if you want buffer to be able to be Uint32Array as in v8 only Uint8Array and Buffer are supported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.