{"record":{"id":"3b1cb929a8a40642","repo":"denoland/deno","slug":"err-invalid-arg-type-3b1cb9","errorCode":"ERR_INVALID_ARG_TYPE","errorMessage":"The \"input\" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received ${actual}","messagePattern":"The \"input\" argument must be of type string or an instance of Buffer, TypedArray, or DataView\\. Received (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/crypto.ts","lineNumber":144,"sourceCode":"  \"crypto.Hmac constructor is deprecated.\",\n  \"DEP0181\",\n);\n\nfunction getRandomValues(typedArray) {\n  return webcrypto.getRandomValues(typedArray);\n}\n\nfunction hash(\n  algorithm: string,\n  data: BinaryLike,\n  outputEncodingOrOptions: BinaryToTextEncoding | {\n    outputEncoding?: BinaryToTextEncoding;\n    outputLength?: number;\n  } = \"hex\",\n) {\n  validateString(algorithm, \"algorithm\");\n  if (typeof data !== \"string\" && !isArrayBufferView(data)) {\n    throw new ERR_INVALID_ARG_TYPE(\"input\", [\n      \"Buffer\",\n      \"TypedArray\",\n      \"DataView\",\n      \"string\",\n    ], data);\n  }\n\n  let outputEncoding: string;\n  let outputLength: number | undefined;\n\n  if (typeof outputEncodingOrOptions === \"object\") {\n    outputEncoding = outputEncodingOrOptions.outputEncoding ?? \"hex\";\n    outputLength = outputEncodingOrOptions.outputLength;\n  } else {\n    outputEncoding = outputEncodingOrOptions;\n  }\n\n  let normalized = outputEncoding;","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/ext/node/polyfills/crypto.ts#L126-L162","documentation":"crypto.hash(algorithm, data, outputEncodingOrOptions) is the one-shot hashing helper. data must be a string or an ArrayBufferView (Buffer, TypedArray, DataView); anything else — numbers, null, booleans, plain objects, BigInts — throws ERR_INVALID_ARG_TYPE for 'input' before hashing.","triggerScenarios":"crypto.hash('sha256', 123); crypto.hash('sha256', null); crypto.hash('sha256', { data: 'x' }). typeof null === 'object' but it is not an ArrayBufferView, so null also throws.","commonSituations":"Hashing values that came from JSON.parse (numbers) without coercion; passing Blob/FormData or other structured objects; code ported from libraries that relied on implicit toString for hashing.","solutions":["Coerce primitives first: crypto.hash('sha256', String(value))","Encode structured data: crypto.hash('sha256', JSON.stringify(obj))","Use Buffer.from(...) to produce a view for binary-ish input"],"exampleFix":"// before\ncrypto.hash(\"sha256\", 123456);\n// after\ncrypto.hash(\"sha256\", String(123456));","handlingStrategy":"type-guard","validationCode":"if (typeof data !== \"string\" && !ArrayBuffer.isView(data)) {\n  throw new TypeError(`crypto.hash data must be string or ArrayBufferView, got ${typeof data}`);\n}","typeGuard":"const isHashable = (d) => typeof d === \"string\" || ArrayBuffer.isView(d);","tryCatchPattern":"try { digest = crypto.hash(algo, data); }\ncatch (e) {\n  if (e.code === \"ERR_INVALID_ARG_TYPE\" && e.message.includes('\"input\"')) {\n    digest = crypto.hash(algo, String(data));\n  } else throw e;\n}","preventionTips":["Stringify values from JSON before hashing","Keep a project helper that always returns string | Uint8Array for hash inputs","Remember null is not hashable even though typeof null === 'object'"],"tags":["crypto","hash","arguments","validation"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}