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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/CryptoEngine/CryptoEngineInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ export function initCryptoEngine() {

common.setEngine(engineName, new CryptoEngine({ name: engineName, crypto: crypto }));
}
} else if (typeof crypto !== "undefined" && "webcrypto" in crypto) {
// NodeJS ^15
const name = "NodeJS ^15";
const nodeCrypto = (crypto as any).webcrypto as Crypto;
common.setEngine(name, new CryptoEngine({ name, crypto: nodeCrypto }));
} else if (typeof crypto !== "undefined") {
if ("webcrypto" in crypto) {
// NodeJS ^15
const name = "NodeJS ^15";
const nodeCrypto = (crypto as any).webcrypto as Crypto;
common.setEngine(name, new CryptoEngine({ name, crypto: nodeCrypto }));
} else if ("subtle" in crypto) {
// NodeJS ^19
const name = "NodeJS ^19";
common.setEngine(name, new CryptoEngine({ name, crypto }));
}
}

}