This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import dotenv from "dotenv"; | |
import { z } from "zod"; | |
dotenv.config(); | |
const envSchema = z.object({ | |
RABBITMQ_URL: z.string().url(), | |
RABBITMQ_QUEUE: z.string().min(1), | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function globalSingleton<T>(key: string, createInstance: () => T): T { | |
const globalStore = globalThis as unknown as Record<string, T | undefined>; | |
if (!globalStore[key]) { | |
globalStore[key] = createInstance(); | |
} | |
return globalStore[key]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type { ProxyInterface } from "telegram/network/connection/TCPMTProxy"; | |
export function mapTelegramProxyString( | |
proxy?: string | |
): ProxyInterface | undefined { | |
const { protocol, hostname, port, username, password } = proxy | |
? new URL(proxy!) | |
: {}; | |
if (proxy) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @example | |
* // Example usage: | |
* let rn = RangedNumber.fromString("1"); | |
* console.log(rn); // RangedNumber { min: 1, mid: 1, max: 1 } | |
* | |
* let rn = RangedNumber.fromString("1-2"); | |
* console.log(rn); // RangedNumber { min: 1, mid: 1.5, max: 2 } | |
* | |
* let randomNumber = rn.get(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import crypto from "crypto"; // npm i crypto | |
/** Helper function to generate a random salt */ | |
export function generateSalt(length: number = 32): string { | |
return crypto.randomBytes(length).toString("hex"); | |
} | |
/** Derive a key from a password and salt */ | |
export function deriveKey(password: string, salt: string): Buffer { | |
return crypto.pbkdf2Sync(password, salt, 100000, 32, "sha256"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import crypto from "crypto"; | |
/** Helper function to generate a random salt */ | |
export function generateSalt(length: number = 32): string { | |
return crypto.randomBytes(length).toString("hex"); | |
} | |
/** Derive a key from a password and salt */ | |
export function deriveKey(password: string, salt: string): Buffer { | |
return crypto.pbkdf2Sync(password, salt, 100000, 32, "sha256"); |