diff --git a/lib/internal/crypto/webcrypto.js b/lib/internal/crypto/webcrypto.js index 47c34b9ca0d665..2f1af95b96a317 100644 --- a/lib/internal/crypto/webcrypto.js +++ b/lib/internal/crypto/webcrypto.js @@ -288,8 +288,11 @@ async function exportKeyRaw(key) { case 'NODE-ED25519': // Fall through case 'NODE-ED448': - return lazyRequire('internal/crypto/ec') - .ecExportKey(key, kWebCryptoKeyFormatRaw); + if (key.type === 'public') { + return lazyRequire('internal/crypto/ec') + .ecExportKey(key, kWebCryptoKeyFormatRaw); + } + break; case 'ECDSA': // Fall through case 'ECDH': diff --git a/test/parallel/test-webcrypto-ed25519-ed448.js b/test/parallel/test-webcrypto-ed25519-ed448.js index 91e0fb8bf3fe0d..9c60ceff64b1b4 100644 --- a/test/parallel/test-webcrypto-ed25519-ed448.js +++ b/test/parallel/test-webcrypto-ed25519-ed448.js @@ -268,15 +268,12 @@ async function test2(namedCurve) { true, ['verify']), ]); - const [ - rawKey1, - rawKey2, - ] = await Promise.all([ - subtle.exportKey('raw', privateKey), - subtle.exportKey('raw', publicKey), - ]); - assert.deepStrictEqual(Buffer.from(rawKey1), vector.privateKey); - assert.deepStrictEqual(Buffer.from(rawKey2), vector.publicKey); + const rawPublicKey = await subtle.exportKey('raw', publicKey); + assert.deepStrictEqual(Buffer.from(rawPublicKey), vector.publicKey); + + assert.rejects(subtle.exportKey('raw', privateKey), { + message: new RegExp(`Unable to export a raw ${namedCurve} private key`) + }).then(common.mustCall()); const sig = await subtle.sign( { name: namedCurve },