{
  "version": 3,
  "sources": ["../src/validateRequest.ts"],
  "sourcesContent": ["import { createHmac } from 'node:crypto'\nimport { RestClient } from '@signalwire/compatibility-api'\n\n/**\n * Utility function to validate an incoming request is indeed from SignalWire\n *\n * @param {string} privateKey - The \"SIGNING KEY\", as seen in the SignalWire API page\n * @param {string} header - The value of the X-SignalWire-Signature header from the request\n * @param {string} url - The full URL (with query string) you configured to handle this request\n * @param {string} rawBody - The raw body of the request (JSON string)\n * @returns {boolean} - Whether the request is valid or not\n */\nexport const validateRequest = (\n  privateKey: string,\n  header: string,\n  url: string,\n  rawBody: string\n): boolean => {\n  if (typeof rawBody !== 'string') {\n    throw new TypeError(\n      `\"rawBody\" is not a string. You may need to JSON.stringify the request body.`\n    )\n  }\n  const hmac = createHmac('sha1', privateKey)\n  hmac.update(`${url}${rawBody}`)\n  const valid = hmac.digest('hex') === header\n\n  if (valid) {\n    return true\n  }\n\n  const parsedBody = JSON.parse(rawBody)\n  // @ts-expect-error - add suppressWarning: true\n  return RestClient.validateRequest(privateKey, header, url, parsedBody, true)\n}\n"],
  "mappings": ";AAAA,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAWpB,IAAM,kBAAkB,CAC7B,YACA,QACA,KACA,YACY;AACZ,MAAI,OAAO,YAAY,UAAU;AAC/B,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,QAAM,OAAO,WAAW,QAAQ,UAAU;AAC1C,OAAK,OAAO,GAAG,GAAG,GAAG,OAAO,EAAE;AAC9B,QAAM,QAAQ,KAAK,OAAO,KAAK,MAAM;AAErC,MAAI,OAAO;AACT,WAAO;AAAA,EACT;AAEA,QAAM,aAAa,KAAK,MAAM,OAAO;AAErC,SAAO,WAAW,gBAAgB,YAAY,QAAQ,KAAK,YAAY,IAAI;AAC7E;",
  "names": []
}
