mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 13:10:56 +00:00
17 lines
672 B
TypeScript
17 lines
672 B
TypeScript
import { OtpTarget } from "../otp/otp.service";
|
|
|
|
/**
|
|
* Mask an OTP target for echoing back to the caller: `+251911234567` ->
|
|
* `+251•••••4567`; `ab@x.com` -> `a•@x.com`. Never return an unmasked target to
|
|
* a caller who has not yet proven possession of the channel.
|
|
*/
|
|
export function maskOtpTarget(target: OtpTarget): string {
|
|
if (target.email) {
|
|
const [local, domain] = target.email.split("@");
|
|
const head = local.slice(0, 1);
|
|
return `${head}${"•".repeat(Math.max(local.length - 1, 1))}@${domain}`;
|
|
}
|
|
const phone = target.phone ?? "";
|
|
return `${phone.slice(0, 4)}${"•".repeat(Math.max(phone.length - 8, 1))}${phone.slice(-4)}`;
|
|
}
|