diff --git a/lib/internal/crypto/aes.js b/lib/internal/crypto/aes.js index 0abffe85c9881b..0474060d394c99 100644 --- a/lib/internal/crypto/aes.js +++ b/lib/internal/crypto/aes.js @@ -5,7 +5,6 @@ const { ArrayBufferPrototypeSlice, ArrayFrom, ArrayPrototypePush, - PromiseReject, SafeSet, TypedArrayPrototypeSlice, } = primordials; @@ -144,7 +143,7 @@ function asyncAesKwCipher(mode, key, data) { getVariant('AES-KW', key[kAlgorithm].length))); } -function asyncAesGcmCipher(mode, key, data, algorithm) { +async function asyncAesGcmCipher(mode, key, data, algorithm) { const { tagLength = 128 } = algorithm; const tagByteLength = tagLength / 8; @@ -160,9 +159,9 @@ function asyncAesGcmCipher(mode, key, data, algorithm) { // > If *plaintext* has a length less than *tagLength* bits, then `throw` // > an `OperationError`. if (tagByteLength > tag.byteLength) { - return PromiseReject(lazyDOMException( + throw lazyDOMException( 'The provided data is too small.', - 'OperationError')); + 'OperationError'); } data = slice(data, 0, -tagByteLength); @@ -173,7 +172,7 @@ function asyncAesGcmCipher(mode, key, data, algorithm) { break; } - return jobPromise(() => new AESCipherJob( + return await jobPromise(() => new AESCipherJob( kCryptoJobAsync, mode, key[kKeyObject][kHandle], @@ -184,7 +183,7 @@ function asyncAesGcmCipher(mode, key, data, algorithm) { algorithm.additionalData)); } -function asyncAesOcbCipher(mode, key, data, algorithm) { +async function asyncAesOcbCipher(mode, key, data, algorithm) { const { tagLength = 128 } = algorithm; const tagByteLength = tagLength / 8; @@ -197,9 +196,9 @@ function asyncAesOcbCipher(mode, key, data, algorithm) { // Similar to GCM, OCB requires the tag to be present for decryption if (tagByteLength > tag.byteLength) { - return PromiseReject(lazyDOMException( + throw lazyDOMException( 'The provided data is too small.', - 'OperationError')); + 'OperationError'); } data = slice(data, 0, -tagByteLength); @@ -210,7 +209,7 @@ function asyncAesOcbCipher(mode, key, data, algorithm) { break; } - return jobPromise(() => new AESCipherJob( + return await jobPromise(() => new AESCipherJob( kCryptoJobAsync, mode, key[kKeyObject][kHandle], @@ -245,12 +244,15 @@ async function aesGenerateKey(algorithm, extractable, keyUsages) { 'SyntaxError'); } - const key = await generateKey('aes', { length }).catch((err) => { + let key; + try { + key = await generateKey('aes', { length }); + } catch (err) { throw lazyDOMException( 'The operation failed for an operation-specific reason' + `[${err.message}]`, { name: 'OperationError', cause: err }); - }); + } return new InternalCryptoKey( key, diff --git a/lib/internal/crypto/cfrg.js b/lib/internal/crypto/cfrg.js index 9380e2a3e746ac..c5bbaae90cf595 100644 --- a/lib/internal/crypto/cfrg.js +++ b/lib/internal/crypto/cfrg.js @@ -149,11 +149,14 @@ async function cfrgGenerateKey(algorithm, extractable, keyUsages) { break; } - const keyPair = await generateKeyPair(genKeyType).catch((err) => { + let keyPair; + try { + keyPair = await generateKeyPair(genKeyType); + } catch (err) { throw lazyDOMException( 'The operation failed for an operation-specific reason', { name: 'OperationError', cause: err }); - }); + } let publicUsages; let privateUsages; @@ -340,14 +343,14 @@ function cfrgImportKey( extractable); } -function eddsaSignVerify(key, data, algorithm, signature) { +async function eddsaSignVerify(key, data, algorithm, signature) { const mode = signature === undefined ? kSignJobModeSign : kSignJobModeVerify; const type = mode === kSignJobModeSign ? 'private' : 'public'; if (key[kKeyType] !== type) throw lazyDOMException(`Key must be a ${type} key`, 'InvalidAccessError'); - return jobPromise(() => new SignJob( + return await jobPromise(() => new SignJob( kCryptoJobAsync, mode, key[kKeyObject][kHandle], diff --git a/lib/internal/crypto/chacha20_poly1305.js b/lib/internal/crypto/chacha20_poly1305.js index bcc778b24d7738..0979d7aaddbb61 100644 --- a/lib/internal/crypto/chacha20_poly1305.js +++ b/lib/internal/crypto/chacha20_poly1305.js @@ -4,7 +4,6 @@ const { ArrayBufferIsView, ArrayBufferPrototypeSlice, ArrayFrom, - PromiseReject, SafeSet, TypedArrayPrototypeSlice, } = primordials; @@ -47,7 +46,7 @@ function validateKeyLength(length) { throw lazyDOMException('Invalid key length', 'DataError'); } -function c20pCipher(mode, key, data, algorithm) { +async function c20pCipher(mode, key, data, algorithm) { let tag; switch (mode) { case kWebCryptoCipherDecrypt: { @@ -55,9 +54,9 @@ function c20pCipher(mode, key, data, algorithm) { TypedArrayPrototypeSlice : ArrayBufferPrototypeSlice; if (data.byteLength < 16) { - return PromiseReject(lazyDOMException( + throw lazyDOMException( 'The provided data is too small.', - 'OperationError')); + 'OperationError'); } tag = slice(data, -16); @@ -69,7 +68,7 @@ function c20pCipher(mode, key, data, algorithm) { break; } - return jobPromise(() => new ChaCha20Poly1305CipherJob( + return await jobPromise(() => new ChaCha20Poly1305CipherJob( kCryptoJobAsync, mode, key[kKeyObject][kHandle], @@ -91,12 +90,15 @@ async function c20pGenerateKey(algorithm, extractable, keyUsages) { 'SyntaxError'); } - const keyData = await randomBytes(32).catch((err) => { + let keyData; + try { + keyData = await randomBytes(32); + } catch (err) { throw lazyDOMException( 'The operation failed for an operation-specific reason' + `[${err.message}]`, { name: 'OperationError', cause: err }); - }); + } return new InternalCryptoKey( createSecretKey(keyData), diff --git a/lib/internal/crypto/ec.js b/lib/internal/crypto/ec.js index c417aa09670f0b..dd7997c82cbf91 100644 --- a/lib/internal/crypto/ec.js +++ b/lib/internal/crypto/ec.js @@ -97,11 +97,14 @@ async function ecGenerateKey(algorithm, extractable, keyUsages) { // Fall through } - const keypair = await generateKeyPair('ec', { namedCurve }).catch((err) => { + let keyPair; + try { + keyPair = await generateKeyPair('ec', { namedCurve }); + } catch (err) { throw lazyDOMException( 'The operation failed for an operation-specific reason', { name: 'OperationError', cause: err }); - }); + } let publicUsages; let privateUsages; @@ -120,14 +123,14 @@ async function ecGenerateKey(algorithm, extractable, keyUsages) { const publicKey = new InternalCryptoKey( - keypair.publicKey, + keyPair.publicKey, keyAlgorithm, publicUsages, true); const privateKey = new InternalCryptoKey( - keypair.privateKey, + keyPair.privateKey, keyAlgorithm, privateUsages, extractable); @@ -281,7 +284,7 @@ function ecImportKey( extractable); } -function ecdsaSignVerify(key, data, { name, hash }, signature) { +async function ecdsaSignVerify(key, data, { name, hash }, signature) { const mode = signature === undefined ? kSignJobModeSign : kSignJobModeVerify; const type = mode === kSignJobModeSign ? 'private' : 'public'; @@ -290,7 +293,7 @@ function ecdsaSignVerify(key, data, { name, hash }, signature) { const hashname = normalizeHashName(hash.name); - return jobPromise(() => new SignJob( + return await jobPromise(() => new SignJob( kCryptoJobAsync, mode, key[kKeyObject][kHandle], diff --git a/lib/internal/crypto/hash.js b/lib/internal/crypto/hash.js index 1c4d1285ec6c34..76129bc989c8f4 100644 --- a/lib/internal/crypto/hash.js +++ b/lib/internal/crypto/hash.js @@ -219,7 +219,7 @@ async function asyncDigest(algorithm, data) { case 'cSHAKE128': // Fall through case 'cSHAKE256': - return jobPromise(() => new HashJob( + return await jobPromise(() => new HashJob( kCryptoJobAsync, normalizeHashName(algorithm.name), data, diff --git a/lib/internal/crypto/mac.js b/lib/internal/crypto/mac.js index 0564f6c19d285f..a31c3ddb0d9484 100644 --- a/lib/internal/crypto/mac.js +++ b/lib/internal/crypto/mac.js @@ -64,11 +64,14 @@ async function hmacGenerateKey(algorithm, extractable, keyUsages) { 'SyntaxError'); } - const key = await generateKey('hmac', { length }).catch((err) => { + let key; + try { + key = await generateKey('hmac', { length }); + } catch (err) { throw lazyDOMException( 'The operation failed for an operation-specific reason', { name: 'OperationError', cause: err }); - }); + } return new InternalCryptoKey( key, @@ -94,12 +97,15 @@ async function kmacGenerateKey(algorithm, extractable, keyUsages) { 'SyntaxError'); } - const keyData = await randomBytes(length / 8).catch((err) => { + let keyData; + try { + keyData = await randomBytes(length / 8); + } catch (err) { throw lazyDOMException( 'The operation failed for an operation-specific reason' + `[${err.message}]`, { name: 'OperationError', cause: err }); - }); + } return new InternalCryptoKey( createSecretKey(keyData), diff --git a/lib/internal/crypto/ml_dsa.js b/lib/internal/crypto/ml_dsa.js index f1e6594f9e1a68..ebe3bfe3d17ca0 100644 --- a/lib/internal/crypto/ml_dsa.js +++ b/lib/internal/crypto/ml_dsa.js @@ -88,11 +88,14 @@ async function mlDsaGenerateKey(algorithm, extractable, keyUsages) { 'SyntaxError'); } - const keyPair = await generateKeyPair(name.toLowerCase()).catch((err) => { + let keyPair; + try { + keyPair = await generateKeyPair(name.toLowerCase()); + } catch (err) { throw lazyDOMException( 'The operation failed for an operation-specific reason', { name: 'OperationError', cause: err }); - }); + } const publicUsages = getUsagesUnion(usageSet, 'verify'); const privateUsages = getUsagesUnion(usageSet, 'sign'); @@ -284,14 +287,14 @@ function mlDsaImportKey( extractable); } -function mlDsaSignVerify(key, data, algorithm, signature) { +async function mlDsaSignVerify(key, data, algorithm, signature) { const mode = signature === undefined ? kSignJobModeSign : kSignJobModeVerify; const type = mode === kSignJobModeSign ? 'private' : 'public'; if (key[kKeyType] !== type) throw lazyDOMException(`Key must be a ${type} key`, 'InvalidAccessError'); - return jobPromise(() => new SignJob( + return await jobPromise(() => new SignJob( kCryptoJobAsync, mode, key[kKeyObject][kHandle], diff --git a/lib/internal/crypto/ml_kem.js b/lib/internal/crypto/ml_kem.js index 5f6efc01125a4b..f6eb76cef10b20 100644 --- a/lib/internal/crypto/ml_kem.js +++ b/lib/internal/crypto/ml_kem.js @@ -59,11 +59,14 @@ async function mlKemGenerateKey(algorithm, extractable, keyUsages) { 'SyntaxError'); } - const keyPair = await generateKeyPair(name.toLowerCase()).catch((err) => { + let keyPair; + try { + keyPair = await generateKeyPair(name.toLowerCase()); + } catch (err) { throw lazyDOMException( 'The operation failed for an operation-specific reason', { name: 'OperationError', cause: err }); - }); + } const publicUsages = getUsagesUnion(usageSet, 'encapsulateBits', 'encapsulateKey'); const privateUsages = getUsagesUnion(usageSet, 'decapsulateBits', 'decapsulateKey'); diff --git a/lib/internal/crypto/rsa.js b/lib/internal/crypto/rsa.js index e3567a98c41878..c6b3985dbaee66 100644 --- a/lib/internal/crypto/rsa.js +++ b/lib/internal/crypto/rsa.js @@ -93,7 +93,7 @@ function validateRsaOaepAlgorithm(algorithm) { } } -function rsaOaepCipher(mode, key, data, algorithm) { +async function rsaOaepCipher(mode, key, data, algorithm) { validateRsaOaepAlgorithm(algorithm); const type = mode === kWebCryptoCipherEncrypt ? 'public' : 'private'; @@ -103,7 +103,7 @@ function rsaOaepCipher(mode, key, data, algorithm) { 'InvalidAccessError'); } - return jobPromise(() => new RSACipherJob( + return await jobPromise(() => new RSACipherJob( kCryptoJobAsync, mode, key[kKeyObject][kHandle], @@ -150,14 +150,17 @@ async function rsaKeyGenerate( } } - const keypair = await generateKeyPair('rsa', { - modulusLength, - publicExponent: publicExponentConverted, - }).catch((err) => { + let keyPair; + try { + keyPair = await generateKeyPair('rsa', { + modulusLength, + publicExponent: publicExponentConverted, + }); + } catch (err) { throw lazyDOMException( 'The operation failed for an operation-specific reason', { name: 'OperationError', cause: err }); - }); + } const keyAlgorithm = { name, @@ -183,14 +186,14 @@ async function rsaKeyGenerate( const publicKey = new InternalCryptoKey( - keypair.publicKey, + keyPair.publicKey, keyAlgorithm, publicUsages, true); const privateKey = new InternalCryptoKey( - keypair.privateKey, + keyPair.privateKey, keyAlgorithm, privateUsages, extractable); @@ -327,14 +330,14 @@ function rsaImportKey( }, keyUsages, extractable); } -function rsaSignVerify(key, data, { saltLength }, signature) { +async function rsaSignVerify(key, data, { saltLength }, signature) { const mode = signature === undefined ? kSignJobModeSign : kSignJobModeVerify; const type = mode === kSignJobModeSign ? 'private' : 'public'; if (key[kKeyType] !== type) throw lazyDOMException(`Key must be a ${type} key`, 'InvalidAccessError'); - return jobPromise(() => { + return await jobPromise(() => { if (key[kAlgorithm].name === 'RSA-PSS') { validateInt32( saltLength, diff --git a/lib/internal/crypto/webcrypto.js b/lib/internal/crypto/webcrypto.js index ba5632c24df7ef..869c07ef87fbe6 100644 --- a/lib/internal/crypto/webcrypto.js +++ b/lib/internal/crypto/webcrypto.js @@ -84,7 +84,7 @@ async function digest(algorithm, data) { algorithm = normalizeAlgorithm(algorithm, 'digest'); - return ReflectApply(asyncDigest, this, [algorithm, data]); + return await ReflectApply(asyncDigest, this, [algorithm, data]); } function randomUUID() { @@ -246,20 +246,20 @@ async function deriveBits(algorithm, baseKey, length = null) { case 'X448': // Fall through case 'ECDH': - return require('internal/crypto/diffiehellman') + return await require('internal/crypto/diffiehellman') .ecdhDeriveBits(algorithm, baseKey, length); case 'HKDF': - return require('internal/crypto/hkdf') + return await require('internal/crypto/hkdf') .hkdfDeriveBits(algorithm, baseKey, length); case 'PBKDF2': - return require('internal/crypto/pbkdf2') + return await require('internal/crypto/pbkdf2') .pbkdf2DeriveBits(algorithm, baseKey, length); case 'Argon2d': // Fall through case 'Argon2i': // Fall through case 'Argon2id': - return require('internal/crypto/argon2') + return await require('internal/crypto/argon2') .argon2DeriveBits(algorithm, baseKey, length); } throw lazyDOMException('Unrecognized algorithm name', 'NotSupportedError'); @@ -391,12 +391,12 @@ async function exportKeySpki(key) { case 'RSA-PSS': // Fall through case 'RSA-OAEP': - return require('internal/crypto/rsa') + return await require('internal/crypto/rsa') .rsaExportKey(key, kWebCryptoKeyFormatSPKI); case 'ECDSA': // Fall through case 'ECDH': - return require('internal/crypto/ec') + return await require('internal/crypto/ec') .ecExportKey(key, kWebCryptoKeyFormatSPKI); case 'Ed25519': // Fall through @@ -405,13 +405,14 @@ async function exportKeySpki(key) { case 'X25519': // Fall through case 'X448': - return require('internal/crypto/cfrg') + return await require('internal/crypto/cfrg') .cfrgExportKey(key, kWebCryptoKeyFormatSPKI); case 'ML-DSA-44': // Fall through case 'ML-DSA-65': // Fall through case 'ML-DSA-87': + // Note: mlDsaExportKey does not return a Promise. return require('internal/crypto/ml_dsa') .mlDsaExportKey(key, kWebCryptoKeyFormatSPKI); case 'ML-KEM-512': @@ -419,6 +420,7 @@ async function exportKeySpki(key) { case 'ML-KEM-768': // Fall through case 'ML-KEM-1024': + // Note: mlKemExportKey does not return a Promise. return require('internal/crypto/ml_kem') .mlKemExportKey(key, kWebCryptoKeyFormatSPKI); default: @@ -433,12 +435,12 @@ async function exportKeyPkcs8(key) { case 'RSA-PSS': // Fall through case 'RSA-OAEP': - return require('internal/crypto/rsa') + return await require('internal/crypto/rsa') .rsaExportKey(key, kWebCryptoKeyFormatPKCS8); case 'ECDSA': // Fall through case 'ECDH': - return require('internal/crypto/ec') + return await require('internal/crypto/ec') .ecExportKey(key, kWebCryptoKeyFormatPKCS8); case 'Ed25519': // Fall through @@ -447,13 +449,14 @@ async function exportKeyPkcs8(key) { case 'X25519': // Fall through case 'X448': - return require('internal/crypto/cfrg') + return await require('internal/crypto/cfrg') .cfrgExportKey(key, kWebCryptoKeyFormatPKCS8); case 'ML-DSA-44': // Fall through case 'ML-DSA-65': // Fall through case 'ML-DSA-87': + // Note: mlDsaExportKey does not return a Promise. return require('internal/crypto/ml_dsa') .mlDsaExportKey(key, kWebCryptoKeyFormatPKCS8); case 'ML-KEM-512': @@ -461,6 +464,7 @@ async function exportKeyPkcs8(key) { case 'ML-KEM-768': // Fall through case 'ML-KEM-1024': + // Note: mlKemExportKey does not return a Promise. return require('internal/crypto/ml_kem') .mlKemExportKey(key, kWebCryptoKeyFormatPKCS8); default: @@ -473,7 +477,7 @@ async function exportKeyRawPublic(key, format) { case 'ECDSA': // Fall through case 'ECDH': - return require('internal/crypto/ec') + return await require('internal/crypto/ec') .ecExportKey(key, kWebCryptoKeyFormatRaw); case 'Ed25519': // Fall through @@ -482,7 +486,7 @@ async function exportKeyRawPublic(key, format) { case 'X25519': // Fall through case 'X448': - return require('internal/crypto/cfrg') + return await require('internal/crypto/cfrg') .cfrgExportKey(key, kWebCryptoKeyFormatRaw); case 'ML-DSA-44': // Fall through @@ -493,6 +497,7 @@ async function exportKeyRawPublic(key, format) { if (format !== 'raw-public') { return undefined; } + // Note: mlDsaExportKey does not return a Promise. return require('internal/crypto/ml_dsa') .mlDsaExportKey(key, kWebCryptoKeyFormatRaw); } @@ -505,6 +510,7 @@ async function exportKeyRawPublic(key, format) { if (format !== 'raw-public') { return undefined; } + // Note: mlKemExportKey does not return a Promise. return require('internal/crypto/ml_kem') .mlKemExportKey(key, kWebCryptoKeyFormatRaw); } @@ -520,6 +526,7 @@ async function exportKeyRawSeed(key) { case 'ML-DSA-65': // Fall through case 'ML-DSA-87': + // Note: mlDsaExportKey does not return a Promise. return require('internal/crypto/ml_dsa') .mlDsaExportKey(key, kWebCryptoKeyFormatRaw); case 'ML-KEM-512': @@ -527,6 +534,7 @@ async function exportKeyRawSeed(key) { case 'ML-KEM-768': // Fall through case 'ML-KEM-1024': + // Note: mlKemExportKey does not return a Promise. return require('internal/crypto/ml_kem') .mlKemExportKey(key, kWebCryptoKeyFormatRaw); default: @@ -933,7 +941,7 @@ async function wrapKey(format, key, wrappingKey, algorithm) { } } - return cipherOrWrap( + return await cipherOrWrap( kWebCryptoCipherEncrypt, algorithm, wrappingKey, @@ -1022,7 +1030,7 @@ async function unwrapKey( ); } -function signVerify(algorithm, key, data, signature) { +async function signVerify(algorithm, key, data, signature) { let usage = 'sign'; if (signature !== undefined) { usage = 'verify'; @@ -1040,31 +1048,31 @@ function signVerify(algorithm, key, data, signature) { case 'RSA-PSS': // Fall through case 'RSASSA-PKCS1-v1_5': - return require('internal/crypto/rsa') + return await require('internal/crypto/rsa') .rsaSignVerify(key, data, algorithm, signature); case 'ECDSA': - return require('internal/crypto/ec') + return await require('internal/crypto/ec') .ecdsaSignVerify(key, data, algorithm, signature); case 'Ed25519': // Fall through case 'Ed448': // Fall through - return require('internal/crypto/cfrg') + return await require('internal/crypto/cfrg') .eddsaSignVerify(key, data, algorithm, signature); case 'HMAC': - return require('internal/crypto/mac') + return await require('internal/crypto/mac') .hmacSignVerify(key, data, algorithm, signature); case 'ML-DSA-44': // Fall through case 'ML-DSA-65': // Fall through case 'ML-DSA-87': - return require('internal/crypto/ml_dsa') + return await require('internal/crypto/ml_dsa') .mlDsaSignVerify(key, data, algorithm, signature); case 'KMAC128': // Fall through case 'KMAC256': - return require('internal/crypto/mac') + return await require('internal/crypto/mac') .kmacSignVerify(key, data, algorithm, signature); } throw lazyDOMException('Unrecognized algorithm name', 'NotSupportedError'); @@ -1089,7 +1097,7 @@ async function sign(algorithm, key, data) { context: '3rd argument', }); - return signVerify(algorithm, key, data); + return await signVerify(algorithm, key, data); } async function verify(algorithm, key, signature, data) { @@ -1115,7 +1123,7 @@ async function verify(algorithm, key, signature, data) { context: '4th argument', }); - return signVerify(algorithm, key, data, signature); + return await signVerify(algorithm, key, data, signature); } async function cipherOrWrap(mode, algorithm, key, data, op) { @@ -1138,7 +1146,7 @@ async function cipherOrWrap(mode, algorithm, key, data, op) { switch (algorithm.name) { case 'RSA-OAEP': - return require('internal/crypto/rsa') + return await require('internal/crypto/rsa') .rsaCipher(mode, key, data, algorithm); case 'AES-CTR': // Fall through @@ -1147,14 +1155,14 @@ async function cipherOrWrap(mode, algorithm, key, data, op) { case 'AES-GCM': // Fall through case 'AES-OCB': - return require('internal/crypto/aes') + return await require('internal/crypto/aes') .aesCipher(mode, key, data, algorithm); case 'ChaCha20-Poly1305': - return require('internal/crypto/chacha20_poly1305') + return await require('internal/crypto/chacha20_poly1305') .c20pCipher(mode, key, data, algorithm); case 'AES-KW': if (op === 'wrapKey' || op === 'unwrapKey') { - return require('internal/crypto/aes') + return await require('internal/crypto/aes') .aesCipher(mode, key, data, algorithm); } } @@ -1181,7 +1189,13 @@ async function encrypt(algorithm, key, data) { }); algorithm = normalizeAlgorithm(algorithm, 'encrypt'); - return cipherOrWrap(kWebCryptoCipherEncrypt, algorithm, key, data, 'encrypt'); + return await cipherOrWrap( + kWebCryptoCipherEncrypt, + algorithm, + key, + data, + 'encrypt', + ); } async function decrypt(algorithm, key, data) { @@ -1204,7 +1218,13 @@ async function decrypt(algorithm, key, data) { }); algorithm = normalizeAlgorithm(algorithm, 'decrypt'); - return cipherOrWrap(kWebCryptoCipherDecrypt, algorithm, key, data, 'decrypt'); + return await cipherOrWrap( + kWebCryptoCipherDecrypt, + algorithm, + key, + data, + 'decrypt', + ); } // Implements https://wicg.github.io/webcrypto-modern-algos/#SubtleCrypto-method-getPublicKey @@ -1267,7 +1287,7 @@ async function encapsulateBits(encapsulationAlgorithm, encapsulationKey) { case 'ML-KEM-512': case 'ML-KEM-768': case 'ML-KEM-1024': - return require('internal/crypto/ml_kem') + return await require('internal/crypto/ml_kem') .mlKemEncapsulate(encapsulationKey); } @@ -1381,7 +1401,7 @@ async function decapsulateBits(decapsulationAlgorithm, decapsulationKey, ciphert case 'ML-KEM-512': case 'ML-KEM-768': case 'ML-KEM-1024': - return require('internal/crypto/ml_kem') + return await require('internal/crypto/ml_kem') .mlKemDecapsulate(decapsulationKey, ciphertext); }