2023-05-18 18:35:39 -04:00
|
|
|
import {createHash} from 'crypto';
|
|
|
|
|
|
|
|
|
|
/**
|
2023-07-04 17:21:34 -04:00
|
|
|
* Returns a hash of `id` prefixed with the first 4 characters of `id`. The first 4
|
|
|
|
|
* characters are included to assist with troubleshooting.
|
2023-05-18 18:35:39 -04:00
|
|
|
*
|
|
|
|
|
* Useful for situations where potentially sensitive identifiers are logged, such as
|
2023-07-04 17:21:34 -04:00
|
|
|
* doc ids of docs that have public link sharing enabled.
|
2023-05-18 18:35:39 -04:00
|
|
|
*/
|
|
|
|
|
export function hashId(id: string): string {
|
|
|
|
|
return `${id.slice(0, 4)}:${createHash('sha256').update(id.slice(4)).digest('base64')}`;
|
|
|
|
|
}
|