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

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

Closed
RedYetiDev opened this issue Sep 23, 2024 · 2 comments
Closed

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

RedYetiDev opened this issue Sep 23, 2024 · 2 comments
Labels
web-standards Issues and PRs related to Web APIs webcrypto

Comments

@RedYetiDev
Copy link
Member

RedYetiDev commented Sep 23, 2024

Node.js is failing the WPT tests added by web-platform-tests/wpt#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 RedYetiDev added webcrypto web-standards Issues and PRs related to Web APIs labels Sep 23, 2024
@RedYetiDev
Copy link
Member Author

RedYetiDev commented Sep 23, 2024

Possible fix?

A possible fix is the following diff, but I'm not a webcrypto expert:

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<KeyUsage>'] = 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
Copy link
Member

panva commented Sep 24, 2024

@RedYetiDev #55041

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
web-standards Issues and PRs related to Web APIs webcrypto
Projects
None yet
Development

No branches or pull requests

2 participants