Skip to content
Closed
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions lib/internal/crypto/webcrypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
15 changes: 6 additions & 9 deletions test/parallel/test-webcrypto-ed25519-ed448.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down