square/js-jose

crypto is not defined

microshine opened this issue · 3 comments

I'm using jose-jwefrom nodejs application. I've got this error on jose-jwe module initialization.
I see it can be fixed by setting global variable crypto.
Maybe it would be better to check if crypto is defined before to use it. This will allow to use setCrypto after module initialization (no need to set global before importconstruction).

example

import * as jose from "jose-jwe";
import * as CryptoOssl from "node-webcrypto-ossl";

jose.setCrypto(new CryptoOssl());

If I set crypto to global before to import jose-jwe, I've got eslint error

eslint: Import in body of module; reorder to top. (import/first)

Seems reasonable to have a setCrypto method. Want to send a PR?

I see this is fixed in master. Any chance of getting a new release?

This fix is in v0.1.6, which I just released.