Files
calendar/packages/lib/videoTokens.ts
T
e2119879ae refactor: apply biome formatting to packages/sms, prisma, emails, lib (#27880)
* refactor: apply biome formatting to small packages + packages/lib

Format packages/sms, packages/prisma, packages/platform/libraries,
packages/platform/examples, packages/platform/types, packages/emails,
and packages/lib.

Excludes packages/platform/examples/base/src/pages/[bookingUid].tsx
due to pre-existing lint errors.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* revert: remove packages/platform formatting changes

Revert biome formatting for packages/platform as requested.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 07:39:01 -03:00

39 lines
1.1 KiB
TypeScript

import { createHmac } from "node:crypto";
// 262992 minutes is 6 months
export function generateVideoToken(recordingId: string, expiresInMinutes = 262992) {
const secret = process.env.CAL_VIDEO_RECORDING_TOKEN_SECRET || "default-secret-change-me";
const expires = Date.now() + expiresInMinutes * 60 * 1000;
const payload = `${recordingId}:${expires}`;
const hmac = createHmac("sha256", secret).update(payload).digest("hex");
return `${payload}:${hmac}`;
}
export function verifyVideoToken(token: string): {
valid: boolean;
recordingId?: string;
} {
try {
const [recordingId, expires, receivedHmac] = token.split(":");
const secret = process.env.CAL_VIDEO_RECORDING_TOKEN_SECRET || "default-secret-change-me";
if (Date.now() > parseInt(expires, 10)) {
return { valid: false };
}
// Verify HMAC
const payload = `${recordingId}:${expires}`;
const expectedHmac = createHmac("sha256", secret).update(payload).digest("hex");
if (receivedHmac !== expectedHmac) {
return { valid: false };
}
return { valid: true, recordingId };
} catch {
return { valid: false };
}
}