You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
16 lines
455 B
16 lines
455 B
import { createHash, randomBytes } from "crypto";
|
|
|
|
const TOKEN_PREFIX = "chj_";
|
|
|
|
export function hashServiceToken(rawToken: string): string {
|
|
return createHash("sha256").update(rawToken, "utf8").digest("hex");
|
|
}
|
|
|
|
export function generateServiceToken(): string {
|
|
return `${TOKEN_PREFIX}${randomBytes(24).toString("base64url")}`;
|
|
}
|
|
|
|
export function tokenKeyPrefix(rawToken: string): string {
|
|
return rawToken.slice(0, Math.min(12, rawToken.length));
|
|
}
|