16 lines
383 B
TypeScript
16 lines
383 B
TypeScript
|
|
import { createHmac } from 'crypto';
|
||
|
|
import { timingSafeEqual } from 'crypto';
|
||
|
|
|
||
|
|
export function verifyDocumensoSignature(
|
||
|
|
payload: string,
|
||
|
|
signature: string,
|
||
|
|
secret: string,
|
||
|
|
): boolean {
|
||
|
|
const hmac = createHmac('sha256', secret).update(payload).digest('hex');
|
||
|
|
try {
|
||
|
|
return timingSafeEqual(Buffer.from(hmac), Buffer.from(signature));
|
||
|
|
} catch {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
}
|