{"record":{"id":"2c3d274bcbc74b7d","repo":"denoland/deno","slug":"invalid-ec-curve-name","errorCode":null,"errorMessage":"Invalid EC curve name","messagePattern":"Invalid EC curve name","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/internal/crypto/diffiehellman.ts","lineNumber":1420,"sourceCode":"        compress = false;\n      } else {\n        throw new ERR_CRYPTO_ECDH_INVALID_FORMAT(format);\n      }\n    } else {\n      compress = false;\n    }\n\n    let result;\n    try {\n      result = Buffer.from(\n        op_node_ecdh_encode_pubkey(curve, buf, compress),\n      );\n    } catch (e) {\n      if (\n        ObjectPrototypeIsPrototypeOf(TypeErrorPrototype, e) &&\n        (e as Error).message === \"Unsupported curve\"\n      ) {\n        throw new TypeError(\"Invalid EC curve name\");\n      }\n      throw new Error(\"Failed to convert Buffer to EC_POINT\");\n    }\n\n    if (format === \"hybrid\") {\n      // Hybrid format: same as uncompressed but first byte is 06 or 07\n      // Get compressed form to determine parity\n      const compressedBuf = Buffer.from(\n        op_node_ecdh_encode_pubkey(curve, buf, true),\n      );\n      // compressed first byte is 02 (even) or 03 (odd)\n      // hybrid first byte is 06 (even) or 07 (odd)\n      result[0] = compressedBuf[0] + 4;\n    }\n\n    if (outputEncoding && outputEncoding !== \"buffer\") {\n      // deno-lint-ignore deno-internal/prefer-primordials -- Buffer.prototype.toString(encoding) has no primordial\n      return result.toString(outputEncoding);","sourceCodeStart":1402,"sourceCodeEnd":1438,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/internal/crypto/diffiehellman.ts#L1402-L1438","documentation":"A TypeError thrown by ECDH.convertKey() when the native op_node_ecdh_encode_pubkey op rejects the curve name with 'Unsupported curve'. Unlike the ECDH constructor (which validates against a JS curve table), convertKey only checks that curve is a string, then hands it straight to the crypto backend; if the backend has no implementation for that curve you get this error instead of the constructor's 'invalid curve'.","triggerScenarios":"ECDH.convertKey(key, 'brainpoolP256r1') or any curve name the native layer does not implement (e.g. brainpool, made-up names, or a typo like 'secp256r1x'), even though the string passes validateString.","commonSituations":"Migrating code from OpenSSL or BouncyCastle that uses brainpool or other exotic curves; typos in curve names; scripts that worked on Node builds with fuller OpenSSL curve support and are re-run under a runtime with a smaller curve set.","solutions":["Use a curve the backend implements: 'prime256v1' (secp256r1), 'secp384r1', 'secp521r1', or 'X25519'","Print/inspect the exact curve string for typos or stray whitespace before the call","If you truly need an unsupported curve, generate the key material with another tool and pass raw buffers, or pick a supported equivalent curve and re-key"],"exampleFix":"// before\nconst out = crypto.ECDH.convertKey(key, 'brainpoolP256r1');\n\n// after\nconst out = crypto.ECDH.convertKey(key, 'prime256v1');","handlingStrategy":"validation","validationCode":"const SUPPORTED = new Set(['prime256v1', 'secp256r1', 'secp384r1', 'secp521r1', 'X25519']);\nif (!SUPPORTED.has(curve)) {\n  throw new RangeError(`unsupported curve '${curve}'; supported: ${[...SUPPORTED].join(', ')}`);\n}\nconst out = crypto.ECDH.convertKey(key, curve, inputEncoding, outputEncoding, format);","typeGuard":null,"tryCatchPattern":"catch (e) { if (e instanceof TypeError && e.message === 'Invalid EC curve name') { /* surface a config error pointing at the curve name */ } throw e; }","preventionTips":["Centralize curve names as constants instead of free-form strings","Trim/normalize curve strings from config files before use","Check curve support at startup rather than mid-handshake"],"tags":["crypto","ecdh","elliptic-curve","node-compat"],"backgroundTag":"unsupported-ec-curve","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}