Skip to content

Support automatic detection of crypto for node 19 and above #438

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

justin-tay
Copy link

Closes #414

Since Node 19 globalThis.crypto now contains an instance to Crypto. This is still true in Node 22. Prior to Node 19 (eg in Node 18) this it was globalThis.crypto.webcrypto. Note that in Node 18, globalThis.crypto is not an instance of Crypto but contains both a subtle member and a webcrypto member.

See https://nodejs.org/docs/latest-v19.x/api/webcrypto.html#web-crypto-api

This isn't caught by tests as the engine gets initialized separately

PKI.js/test/utils.ts

Lines 53 to 59 in 06f154a

if (isNode()) {
import("@peculiar/webcrypto").then(peculiarCrypto => {
const webcrypto = new peculiarCrypto.Crypto();
const name = "newEngine";
pkijs.setEngine(name, new pkijs.CryptoEngine({ name, crypto: webcrypto }));
});
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Automatic crypto engine detection fails in a vitest environment
1 participant