Files
calendar/packages/lib/server/PiiHasher.ts
T
Anik Dhabal BabuandGitHub ee70111c45 fix: RateLimit verify email and fix (#23718)
* fix: RateLimit verify email

* update

* client chnages

* type error

* fix

* add test

* Update event-types.e2e.ts

* minor update

* Update event-types.e2e.ts

* fix test

* handle it in api v2
2025-09-12 18:27:05 +01:00

23 lines
677 B
TypeScript

import { createHash } from "crypto";
export interface PiiHasher {
hash(input: string): string;
}
export class Md5PiiHasher implements PiiHasher {
constructor(private readonly salt: string) {}
hash(input: string) {
return createHash("md5")
.update(this.salt + input)
.digest("hex");
}
}
export const piiHasher: PiiHasher = new Md5PiiHasher(process.env.CALENDSO_ENCRYPTION_KEY!);
export const hashEmail = (email: string, hasher: PiiHasher = piiHasher): string => {
const [localPart, domain] = email.split("@");
// Simple hash function for email, can be replaced with a more complex one if needed
return `${hasher.hash(localPart)}@${domain}`;
};