2023-05-18 22:35:39 +00:00
|
|
|
import {createHash} from 'crypto';
|
|
|
|
|
|
|
|
/**
|
2023-07-04 21:21:34 +00: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 22:35:39 +00:00
|
|
|
*
|
|
|
|
* Useful for situations where potentially sensitive identifiers are logged, such as
|
2023-07-04 21:21:34 +00:00
|
|
|
* doc ids of docs that have public link sharing enabled.
|
2023-05-18 22:35:39 +00:00
|
|
|
*/
|
|
|
|
export function hashId(id: string): string {
|
|
|
|
return `${id.slice(0, 4)}:${createHash('sha256').update(id.slice(4)).digest('base64')}`;
|
|
|
|
}
|