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

fix: favor globalThis.crypto over require('crypto') #1

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 2 additions & 4 deletions packages/pg/lib/crypto/utils-webcrypto.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const nodeCrypto = require('crypto')

module.exports = {
postgresMd5PasswordHash,
randomBytes,
Expand All @@ -13,7 +11,7 @@ module.exports = {
* The Web Crypto API - grabbed from the Node.js library or the global
* @type Crypto
*/
const webCrypto = nodeCrypto.webcrypto || globalThis.crypto
const webCrypto = globalThis.crypto || require('crypto').webcrypto
/**
* The SubtleCrypto API for low level crypto operations.
* @type SubtleCrypto
Expand All @@ -32,7 +30,7 @@ function randomBytes(length) {

async function md5(string) {
try {
return nodeCrypto.createHash('md5').update(string, 'utf-8').digest('hex')
return require('crypto').createHash('md5').update(string, 'utf-8').digest('hex')
} catch (e) {
// `createHash()` failed so we are probably not in Node.js, use the WebCrypto API instead.
// Note that the MD5 algorithm on WebCrypto is not available in Node.js.
Expand Down