Skip to content
Source
Sign inSign up

telemetryId.ts

12 lines554 Bytes

1import { sha256 } from "@noble/hashes/sha2";
2import * as Hex from "effect/encoding/Hex";
3​
4/**
5 * Hashes an identifier before it reaches analytics. Clients and the server both
6 * use it, so one Connect account gives the same owner id on every surface.
7 */
8export const hashTelemetryId = (value: string): string =>
9 Hex.encode(sha256(new TextEncoder().encode(value)));
10​
11/** True for a `hashTelemetryId` result. The server accepts only this shape from clients. */
12export const isTelemetryIdHash = (value: string): boolean => /^[0-9a-f]{64}$/u.test(value);