{"record":{"id":"1f3be02aa7dfbb1b","repo":"denoland/deno","slug":"err-invalid-arg-type-1f3be0","errorCode":"ERR_INVALID_ARG_TYPE","errorMessage":"The \"signature\" argument must be an instance of Buffer, TypedArray, or DataView. Received ${signature}","messagePattern":"The \"signature\" argument must be an instance of Buffer, TypedArray, or DataView\\. Received (.+?)","errorType":"error_code","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/internal/crypto/sig.ts","lineNumber":292,"sourceCode":"      throw new Error(`Invalid digest: ${algorithm}`);\n    }\n  }\n\n  update(data: any, encoding?: string): this {\n    this.hash.update(data, encoding);\n    return this;\n  }\n\n  verify(\n    publicKey: any,\n    signature: any,\n    encoding?: any,\n  ): boolean {\n    if (\n      typeof signature !== \"string\" &&\n      !ArrayBufferIsView(signature)\n    ) {\n      throw new ERR_INVALID_ARG_TYPE(\n        \"signature\",\n        [\"Buffer\", \"TypedArray\", \"DataView\"],\n        signature,\n      );\n    }\n    const res = prepareAsymmetricKey(publicKey, kConsumePublic);\n\n    // Options specific to RSA\n    const rsaPadding = getPadding(publicKey);\n\n    // Options specific to RSA-PSS\n    const pssSaltLength = getSaltLength(publicKey);\n\n    // Options specific to (EC)DSA\n    const dsaSigEnc = getDSASignatureEncoding(publicKey);\n\n    let handle;\n    if (ReflectHas(res, \"handle\")) {","sourceCodeStart":274,"sourceCodeEnd":310,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/internal/crypto/sig.ts#L274-L310","documentation":"Verify.verify(publicKey, signature, encoding) requires signature to be a string or an ArrayBufferView (Buffer, TypedArray, DataView); any other value throws ERR_INVALID_ARG_TYPE. A raw ArrayBuffer is rejected because it is not a view — only the bytes are needed, so wrap it. Strings are later decoded using the third encoding argument.","triggerScenarios":"verify.verify(pubKey, sig) where sig is an ArrayBuffer from response.arrayBuffer(); a number, null, plain object, or undefined in the signature slot; passing a parsed JSON object that contains the signature bytes.","commonSituations":"Verifying signatures received over HTTP (fetch's res.arrayBuffer() returns an ArrayBuffer, not a view); WebCrypto interop where subtle operations return ArrayBuffers; passing base64 text without Buffer.from(sig, \"base64\").","solutions":["Wrap ArrayBuffers: verify.verify(pubKey, new Uint8Array(ab)) or Buffer.from(ab).","Convert encoded signatures explicitly: Buffer.from(base64Sig, \"base64\").","Check the signature variable is defined and not shadowed before calling verify()."],"exampleFix":"// before\nconst sig = await res.arrayBuffer(); // ArrayBuffer, not a view\nverifier.verify(pubKey, sig); // throws\n\n// after\nconst sig = new Uint8Array(await res.arrayBuffer());\nverifier.verify(pubKey, sig);","handlingStrategy":"type-guard","validationCode":"function toSignatureBytes(sig) {\n  if (typeof sig === \"string\") return Buffer.from(sig, \"base64\");\n  if (ArrayBuffer.isView(sig)) return Buffer.from(sig);\n  throw new TypeError(`signature must be string or TypedArray, got ${typeof sig}`);\n}\nverifier.verify(pubKey, toSignatureBytes(sigFromHttp));","typeGuard":"const isSignaturable = (v) => typeof v === \"string\" || ArrayBuffer.isView(v);","tryCatchPattern":"try {\n  ok = verifier.verify(pubKey, sig);\n} catch (e) {\n  if (e?.code === \"ERR_INVALID_ARG_TYPE\" && /^The \"signature\"/.test(e.message)) {\n    return res.status(400).end(\"malformed signature payload\");\n  }\n  throw e;\n}","preventionTips":["Wrap fetch/arrayBuffer() results in new Uint8Array(...) at the boundary of your app.","Standardize on Buffer internally; convert once at the edge.","An ArrayBuffer is not a view — the check here rejects it even though it holds the right bytes."],"tags":["crypto","verification","buffer","argument-type"],"backgroundTag":"invalid-argument-value","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}