Socket connection now works

- Pairing a new device works

(I did a lot since the last commit)
This commit is contained in:
2021-11-14 01:42:21 +01:00
parent 28e85ea730
commit 19b7c05d75
72 changed files with 5861 additions and 23719 deletions

View File

@@ -1,6 +1,7 @@
import { hash, verify } from 'argon2';
import { verify as jwtVerify } from 'jsonwebtoken';
import { config } from '../config';
import { IS_DEBUG, logger } from '../app';
import { IS_DEBUG, JWT_SECRET, logger } from '../app';
export async function hashPassword(input: string): Promise<string> {
const start = Date.now();
@@ -64,9 +65,19 @@ export async function verifyPassword(password: string, hashInput: string): Promi
});
}
export function randomString(length: number): string {
export async function verifyJWT(token: string): Promise<boolean> {
return new Promise<boolean>(async (resolve, reject) => {
try {
jwtVerify(token, JWT_SECRET, { algorithms: ['HS256'] });
resolve(true);
} catch {
resolve(false);
}
});
}
export function randomString(length: number, characters: string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'): string {
let result = '';
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
const charactersLength = characters.length;
for ( let i = 0; i < length; i++ ) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));