mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-18 09:20:15 +01:00
18 lines
537 B
TypeScript
18 lines
537 B
TypeScript
|
|
import jwt from 'jsonwebtoken';
|
||
|
|
import { webcrypto } from 'node:crypto';
|
||
|
|
import { SignPayloadParams } from '~/types';
|
||
|
|
|
||
|
|
export async function signPayload({
|
||
|
|
payload,
|
||
|
|
secret,
|
||
|
|
expirationTime,
|
||
|
|
}: SignPayloadParams): Promise<string> {
|
||
|
|
return jwt.sign(payload, secret!, { expiresIn: expirationTime });
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function hashToken(str: string): Promise<string> {
|
||
|
|
const data = new TextEncoder().encode(str);
|
||
|
|
const hashBuffer = await webcrypto.subtle.digest('SHA-256', data);
|
||
|
|
return Buffer.from(hashBuffer).toString('hex');
|
||
|
|
}
|