{"record":{"id":"2e0bd5c7a4eb17bf","repo":"denoland/deno","slug":"err-invalid-arg-value-2e0bd5","errorCode":"ERR_INVALID_ARG_VALUE","errorMessage":"The property 'options.privateKey' is invalid. Received ${options.privateKey}","messagePattern":"The property 'options\\.privateKey' is invalid\\. Received (.+?)","errorType":"exception","errorClass":"ERR_INVALID_ARG_VALUE","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/internal/crypto/diffiehellman.ts","lineNumber":1649,"sourceCode":"}\n\nfunction diffieHellman(\n  options: {\n    privateKey: KeyObject;\n    publicKey: KeyObject;\n  },\n  callback?: (err: Error | null, secret?: Buffer) => void,\n): Buffer | void {\n  if (callback !== undefined && typeof callback !== \"function\") {\n    throw new ERR_INVALID_ARG_TYPE(\"callback\", \"function\", callback);\n  }\n  if (\n    typeof options !== \"object\" || options === null || ArrayIsArray(options)\n  ) {\n    throw new ERR_INVALID_ARG_TYPE(\"options\", \"object\", options);\n  }\n  if (!options.privateKey) {\n    throw new ERR_INVALID_ARG_VALUE(\"options.privateKey\", options.privateKey);\n  }\n  if (!options.publicKey) {\n    throw new ERR_INVALID_ARG_VALUE(\"options.publicKey\", options.publicKey);\n  }\n\n  if (callback) {\n    try {\n      const secret = statelessDH(options.privateKey, options.publicKey);\n      callback(null, secret);\n    } catch (err) {\n      callback(err as Error);\n    }\n    return;\n  }\n\n  return statelessDH(options.privateKey, options.publicKey);\n}\n","sourceCodeStart":1631,"sourceCodeEnd":1667,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/internal/crypto/diffiehellman.ts#L1631-L1667","documentation":"The options object passed to crypto.diffieHellman() must contain a truthy privateKey; a missing, undefined, or null value throws ERR_INVALID_ARG_VALUE for 'options.privateKey'. This is a presence check only — an incorrect type is caught later when the key handle is consumed.","triggerScenarios":"diffieHellman({ publicKey }) with privateKey omitted; destructuring typos ({ privateKey: pub }); optional-chained config where the private key failed to load and is undefined.","commonSituations":"Env-driven key loading where a missing env var silently yields undefined; mocks/stubs in tests that build partial options; copy-paste between the privateKey and publicKey fields.","solutions":["Supply options.privateKey as a KeyObject from crypto.createPrivateKey()","Fail fast at startup when required key material cannot be loaded, instead of passing undefined through","Add a runtime assertion or schema check on the options object before calling"],"exampleFix":"// before\ndiffieHellman({ publicKey: theirPub });\n\n// after\ndiffieHellman({ privateKey: myPriv, publicKey: theirPub });","handlingStrategy":"validation","validationCode":"if (!options?.privateKey) {\n  throw new Error('privateKey missing: load it with crypto.createPrivateKey before DH');\n}\ncrypto.diffieHellman(options);","typeGuard":"const hasPrivateKey = (o: unknown): o is { privateKey: crypto.KeyObject } =>\n  typeof o === 'object' && o !== null && (o as any).privateKey?.type === 'private';","tryCatchPattern":null,"preventionTips":["Fail fast when key material fails to load instead of passing undefined","Check required options at the boundary of your wrapper, not inside crypto","Use TypeScript's exhaustiveness on the options type"],"tags":["crypto","diffie-hellman","argument-validation","node-compat"],"backgroundTag":"missing-required-option","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-21T10:36:37.832Z"}