nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
107.3k stars 29.45k forks source link

Node.js failing ECDH and ECDSA importKey() WPT #55090

Closed RedYetiDev closed 3 weeks ago

RedYetiDev commented 3 weeks ago

Node.js is failing the WPT tests added by https://github.com/web-platform-tests/wpt/pull/48243

All the errors appear to be expected "DataError" but got "TypeError", so it looks like Node.js is returning the wrong errors.

Ref: https://developer.mozilla.org/en-US/docs/Web/API/DOMException#dataerror

RedYetiDev commented 3 weeks ago
Possible fix? A possible fix is the following diff, but I'm not a webcrypto expert: ```diff diff --git a/lib/internal/crypto/webidl.js b/lib/internal/crypto/webidl.js index ee9b7b69b7..a927fe877b 100644 --- a/lib/internal/crypto/webidl.js +++ b/lib/internal/crypto/webidl.js @@ -317,7 +317,7 @@ converters.KeyFormat = createEnumConverter('KeyFormat', [ 'pkcs8', 'spki', 'jwk', -]); +], 'DataError'); converters.KeyUsage = createEnumConverter('KeyUsage', [ 'encrypt', @@ -328,7 +328,7 @@ converters.KeyUsage = createEnumConverter('KeyUsage', [ 'deriveBits', 'wrapKey', 'unwrapKey', -]); +], 'DataError'); converters['sequence'] = createSequenceConverter(converters.KeyUsage); diff --git a/lib/internal/webidl.js b/lib/internal/webidl.js index 9e4b20435b..e811b0e8d0 100644 --- a/lib/internal/webidl.js +++ b/lib/internal/webidl.js @@ -204,7 +204,7 @@ function makeException(message, opts = kEmptyObject) { ); } -function createEnumConverter(name, values) { +function createEnumConverter(name, values, errorName = 'TypeError') { const E = new SafeSet(values); return function(V, opts = kEmptyObject) { @@ -213,7 +213,7 @@ function createEnumConverter(name, values) { if (!E.has(S)) { throw makeException( `value '${S}' is not a valid enum value of type ${name}.`, - { __proto__: null, ...opts, code: 'ERR_INVALID_ARG_VALUE' }); + { __proto__: null, ...opts, code: 'ERR_INVALID_ARG_VALUE', name: errorName }); } return S; ```
panva commented 3 weeks ago

@RedYetiDev #55041