{"record":{"id":"e7c49124eab8a274","repo":"denoland/deno","slug":"err-invalid-arg-type-e7c491","errorCode":"ERR_INVALID_ARG_TYPE","errorMessage":"The \"sizeOrKey\" argument must be one of type number or string or an instance of ArrayBuffer, Buffer, TypedArray, or DataView","messagePattern":"The \"sizeOrKey\" argument must be one of type number or string or an instance of ArrayBuffer, Buffer, TypedArray, or DataView","errorType":"validation","errorClass":"NodeTypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/internal/crypto/diffiehellman.ts","lineNumber":129,"sourceCode":"  #primeLength: number;\n  #generator: Buffer;\n  #privateKey: Buffer;\n  #publicKey: Buffer;\n  #publicKeyNeedsUpdate = false;\n\n  constructor(\n    sizeOrKey: number | string | ArrayBufferView,\n    keyEncoding?: unknown,\n    generator?: unknown,\n    genEncoding?: unknown,\n  ) {\n    if (\n      typeof sizeOrKey !== \"number\" &&\n      typeof sizeOrKey !== \"string\" &&\n      !isArrayBufferView(sizeOrKey) &&\n      !isAnyArrayBuffer(sizeOrKey)\n    ) {\n      throw new ERR_INVALID_ARG_TYPE(\n        \"sizeOrKey\",\n        [\n          \"number\",\n          \"string\",\n          \"ArrayBuffer\",\n          \"Buffer\",\n          \"TypedArray\",\n          \"DataView\",\n        ],\n        sizeOrKey,\n      );\n    }\n\n    if (typeof sizeOrKey === \"number\") {\n      validateInt32(sizeOrKey, \"sizeOrKey\");\n    }\n\n    if (","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/internal/crypto/diffiehellman.ts#L111-L147","documentation":"The DiffieHellman constructor (diffiehellman.ts:129) requires sizeOrKey to be a number (prime bit length), a string (encoded prime), or binary data (Buffer/TypedArray/DataView/ArrayBuffer). Anything else throws ERR_INVALID_ARG_TYPE enumerating all accepted types. BigInt is the frequent offender because it is none of the above.","triggerScenarios":"new DiffieHellman(BigInt(prime)) or a BigInt produced by a big-number library; passing null/undefined/plain objects; passing a DH params object ({ prime }) instead of its field.","commonSituations":"Primes arriving from bignum/BN.js computations as BigInt; JSON config objects passed wholesale; argument order mix-ups where keyEncoding lands in sizeOrKey's slot.","solutions":["Convert BigInt primes to Buffer: Buffer.from(prime.toString(16), 'hex')","Pass the bit length as a number, or the prime as a Buffer","Destructure params objects before constructing: new DiffieHellman(params.prime, 2)"],"exampleFix":"// before\nnew DiffieHellman(bigIntPrime); // BigInt rejected\n\n// after\nnew DiffieHellman(Buffer.from(bigIntPrime.toString(16), 'hex'), 2);","handlingStrategy":"type-guard","validationCode":"function isValidSizeOrKey(v) {\n  return typeof v === 'number' || typeof v === 'string' || ArrayBuffer.isView(v) || v instanceof ArrayBuffer;\n}","typeGuard":"const isSizeOrKey = (v) => typeof v === 'number' || typeof v === 'string' || ArrayBuffer.isView(v) || v instanceof ArrayBuffer;","tryCatchPattern":null,"preventionTips":["Normalize prime material to Buffer at the edge of your module (BigInt -> hex -> Buffer)","Use TypeScript types (number | string | ArrayBufferView) on wrappers to catch misuse at compile time"],"tags":["crypto","diffiehellman","validation","node-compat"],"backgroundTag":"invalid-argument-type","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}