/* eslint-disable consistent-return */ import { createReadStream } from 'fs' import readline from 'readline' import { AuthKeys } from '../../types' import { Response } from './types' export async function ServerUtils_GetAuthKeys(path: string): Promise { // Rotate the key // Make the key something unique to all services. // the key could be made up of the domain and also the service name, and another key that the company creates as well. // We could make this done on init. Which is then completely encrypted, // Then we can use this across services, so the key will always be the same and also rotated based on the timestamp // Each time it's rotated. WAPI will generate a new encyption based on // The goal: // for each service in a cluster to be able to talk to each other, once the person is verified. // It will generate a encrypted JWT that is passed back and forth. // When it rotates every 20 mins, it will remember in memory the last [X] keys, based on the server setup. // try { const fileStream = createReadStream(path) const rl = readline.createInterface({ input: fileStream, crlfDelay: Infinity, }) // Note: we use the crlfDelay option to recognize all instances of CR LF const keys: string[] = [] // eslint-disable-next-line no-restricted-syntax for await (const line of rl) { keys.push(line) } return { current: keys[0], previous: keys[1] } } catch (err) { console.error(err) return { current: '', previous: '', } } }