use crypto package instead

This commit is contained in:
2026-05-03 22:44:48 -04:00
parent a4684e9121
commit f2593c1e67
2 changed files with 8 additions and 8 deletions

View File

@@ -1,12 +1,10 @@
import crypto from 'crypto';
/**
* Hash a phone number for analytics purposes
* Uses a consistent hashing algorithm to create a deterministic hash
* Uses SHA-256 for consistent, cryptographically strong hashing
*/
export function hashPhoneNumber(phoneNumber: string): string {
let hash = 0;
for (let i = 0; i < phoneNumber.length; i++) {
hash = ((hash << 5) - hash) + phoneNumber.charCodeAt(i);
hash |= 0;
}
return `hash_${Math.abs(hash)}`;
const hash = crypto.createHash('sha256').update(phoneNumber).digest('hex');
return `sha256_${hash}`;
}