{"record":{"id":"1d194b85756c73d9","repo":"denoland/deno","slug":"err-invalid-arg-value-1d194b","errorCode":"ERR_INVALID_ARG_VALUE","errorMessage":"The argument 'type' is invalid. Received ${inspected}","messagePattern":"The argument 'type' is invalid\\. Received (.+?)","errorType":"error_code","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/internal/crypto/keys.ts","lineNumber":157,"sourceCode":"        buffer,\n      );\n    }\n    return buffer;\n  },\n);\n\nconst kConsumePublic = 0;\nconst kConsumePrivate = 1;\nconst kCreatePublic = 2;\nconst kCreatePrivate = 3;\n\nclass KeyObject {\n  [kKeyType]: any;\n  [kHandle]: any;\n\n  constructor(type: any, handle: any) {\n    if (type !== \"secret\" && type !== \"public\" && type !== \"private\") {\n      throw new ERR_INVALID_ARG_VALUE(\"type\", type);\n    }\n\n    if (typeof handle !== \"object\") {\n      throw new ERR_INVALID_ARG_TYPE(\"handle\", \"object\", handle);\n    }\n\n    this[kKeyType] = type;\n    this[kHandle] = handle;\n  }\n\n  get type(): any {\n    return this[kKeyType];\n  }\n\n  static from(key: CryptoKey): KeyObject {\n    if (!isCryptoKey(key)) {\n      throw new ERR_INVALID_ARG_TYPE(\"key\", \"CryptoKey\", key);\n    }","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/internal/crypto/keys.ts#L139-L175","documentation":"KeyObject's constructor only accepts the internal type strings 'secret', 'public', and 'private'. It is an internal API meant to be called by the crypto factories; constructing crypto.KeyObject directly with any other type string (e.g. an algorithm name like 'rsa') throws ERR_INVALID_ARG_VALUE for 'type'.","triggerScenarios":"new crypto.KeyObject('rsa', handle) or new crypto.KeyObject('Secret', handle) — application code calling the constructor directly instead of using the factory APIs.","commonSituations":"Attempting to hand-fabricate a KeyObject around raw key data; porting code from libraries that poke at Node internals; assuming the constructor validates algorithm names.","solutions":["Build KeyObjects with the factory APIs: crypto.createSecretKey(data), crypto.createPublicKey(...), crypto.createPrivateKey(...)","Never call new crypto.KeyObject() from application code; treat it as internal","If you only have raw bytes, createSecretKey(bytes) gives a valid secret KeyObject"],"exampleFix":"// before\nconst k = new crypto.KeyObject('secret', rawBytes);\n// after\nconst k = crypto.createSecretKey(rawBytes);","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"const KEY_OBJECT_TYPES = ['secret', 'public', 'private'];\nfunction isKeyObjectType(t) {\n  return KEY_OBJECT_TYPES.includes(t);\n}","tryCatchPattern":null,"preventionTips":["Treat new crypto.KeyObject() as off-limits in application code","Always obtain KeyObjects from createSecretKey/createPublicKey/createPrivateKey or generateKeyPair","Lint for 'new crypto.KeyObject' occurrences in CI"],"tags":["crypto","keyobject","node-compat"],"backgroundTag":"invalid-key-type","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}