{"record":{"id":"ac3cf89f6f370bb9","repo":"denoland/deno","slug":"err-invalid-arg-value-ac3cf8","errorCode":"ERR_INVALID_ARG_VALUE","errorMessage":"The argument 'type' must be a supported key type. Received ${type}","messagePattern":"The argument 'type' must be a supported key type\\. Received (.+?)","errorType":"exception","errorClass":"ERR_INVALID_ARG_VALUE","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/internal/crypto/keygen.ts","lineNumber":89,"sourceCode":"  op_node_get_public_key_from_pair,\n} = core.ops;\n\nfunction validateGenerateKey(\n  type: \"hmac\" | \"aes\",\n  options: { length: number },\n) {\n  validateString(type, \"type\");\n  validateObject(options, \"options\");\n  const { length } = options;\n  switch (type) {\n    case \"hmac\":\n      validateInteger(length, \"options.length\", 8, 2 ** 31 - 1);\n      break;\n    case \"aes\":\n      validateOneOf(length, \"options.length\", kAesKeyLengths);\n      break;\n    default:\n      throw new ERR_INVALID_ARG_VALUE(\n        \"type\",\n        type,\n        \"must be a supported key type\",\n      );\n  }\n}\n\nfunction generateKeySync(\n  type: \"hmac\" | \"aes\",\n  options: {\n    length: number;\n  },\n): KeyObject {\n  validateGenerateKey(type, options);\n  const { length } = options;\n\n  const len = Math.floor(length / 8);\n","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/internal/crypto/keygen.ts#L71-L107","documentation":"crypto.generateKey and generateKeySync only create symmetric secret keys, so their option validator (ext/node/polyfills/internal/crypto/keygen.ts:81-95) accepts exactly type 'hmac' (integer length 8..2^31-1) or 'aes' (length one of 128/192/256). Any other type string falls into the default branch and throws ERR_INVALID_ARG_VALUE with 'must be a supported key type'.","triggerScenarios":"crypto.generateKeySync('rsa', { length: 2048 }); generateKeySync('ed25519', {...}); generateKeySync('aes', { length: 100 }); generateKey('hmac', { length: 4 }) throws a validateInteger error instead - the type throw is specifically for names outside {hmac, aes}.","commonSituations":"Assuming generateKey is a general-purpose generator and trying to make RSA/EC/Ed25519 keys with it; migrating from WebCrypto generateKey (which does handle asymmetric types) to node:crypto; JSON configs driving the 'type' field.","solutions":["Use crypto.generateKeyPair[Sync] for asymmetric keys (rsa, ec, ed25519, dh...).","Use generateKey('hmac', { length: 256 }) or generateKey('aes', { length: 128|192|256 }) for symmetric secrets.","Validate the type against ['hmac','aes'] before calling when it comes from config or user input."],"exampleFix":"// before\ncrypto.generateKeySync('rsa', { length: 2048 }); // ERR_INVALID_ARG_VALUE: unsupported type\n\n// after\nconst hmacKey = crypto.generateKeySync('hmac', { length: 256 });\nconst aesKey = crypto.generateKeySync('aes', { length: 256 });\nconst { publicKey, privateKey } = crypto.generateKeyPairSync('rsa', {\n  modulusLength: 2048,\n});","handlingStrategy":"validation","validationCode":"const SECRET_TYPES = new Set(['hmac', 'aes']);\nfunction generateSecret(type, options) {\n  if (!SECRET_TYPES.has(type)) {\n    throw new Error(`generateKey supports ${[...SECRET_TYPES]}; use generateKeyPair for '${type}'`);\n  }\n  return crypto.generateKeySync(type, options);\n}","typeGuard":"function isSecretKeyType(t) {\n  return t === 'hmac' || t === 'aes';\n}","tryCatchPattern":"try {\n  key = crypto.generateKeySync(type, opts);\n} catch (e) {\n  if (e.code === 'ERR_INVALID_ARG_VALUE' && /type/.test(e.message)) {\n    ({ publicKey, privateKey } = crypto.generateKeyPairSync(type, pairOpts(type)));\n  } else throw e;\n}","preventionTips":["Remember generateKey = symmetric secrets only (hmac/aes); generateKeyPair = asymmetric.","Validate the type string when it comes from config or user input.","For aes, restrict length to 128/192/256; for hmac, an integer byte length >= 8."],"tags":["crypto","key-generation","node-compat","argument-validation"],"backgroundTag":"unsupported-key-type","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}