Options
All
  • Public
  • Public/Protected
  • All
Menu

Namespace helpers

Index

Functions

  • readBigIntFromBuffer(buffer: Buffer, little?: boolean, signed?: boolean): bigInt.BigInteger
  • converts a buffer to big int

    Parameters

    • buffer: Buffer
    • little: boolean = true
    • signed: boolean = false

    Returns bigInt.BigInteger

  • generateRandomBigInt(): BigInteger
  • escapeRegex(string: string): string
  • groupBy(list: any[], keyGetter: Function): Map<any, any>
  • betterConsoleLog(object: {}): {}
  • Outputs the object in a better way by hiding all the private methods/attributes.

    Parameters

    • object: {}

      the class to use

      • [key: string]: any

    Returns {}

    • [key: string]: any
  • isArrayLike<T>(x: any): x is T[]
  • Helper to find if a given object is an array (or similar)

    Type Parameters

    • T

    Parameters

    • x: any

    Returns x is T[]

  • toSignedLittleBuffer(big: string | number | BigInteger, number?: number): Buffer
  • Special case signed little ints

    Parameters

    • big: string | number | BigInteger
    • number: number = 8

    Returns Buffer

  • readBufferFromBigInt(bigIntVar: BigInteger, bytesNumber: number, little?: boolean, signed?: boolean): Buffer
  • converts a big int to a buffer

    Parameters

    • bigIntVar: BigInteger
    • bytesNumber: number
    • little: boolean = true
    • signed: boolean = false

    Returns Buffer

  • generateRandomLong(signed?: boolean): BigInteger
  • Generates a random long integer (8 bytes), which is optionally signed

    Parameters

    • signed: boolean = true

    Returns BigInteger

  • mod(n: number, m: number): number
  • bigIntMod(n: BigInteger, m: BigInteger): bigInt.BigInteger
  • returns a positive bigInt

    Parameters

    • n: BigInteger
    • m: BigInteger

    Returns bigInt.BigInteger

  • generateRandomBytes(count: number): Buffer
  • generateKeyDataFromNonce(serverNonceBigInt: BigInteger, newNonceBigInt: BigInteger): Promise<{ key: Buffer; iv: Buffer }>
  • Generates the key data corresponding to the given nonces

    Parameters

    • serverNonceBigInt: BigInteger
    • newNonceBigInt: BigInteger

    Returns Promise<{ key: Buffer; iv: Buffer }>

  • convertToLittle(buf: Buffer): Buffer
  • sha1(data: Buffer): Promise<Buffer>
  • Calculates the SHA1 digest for the given data

    Parameters

    • data: Buffer

    Returns Promise<Buffer>

  • sha256(data: Buffer): Promise<Buffer>
  • Calculates the SHA256 digest for the given data

    Parameters

    • data: Buffer

    Returns Promise<Buffer>

  • modExp(a: BigInteger, b: BigInteger, n: BigInteger): bigInt.BigInteger
  • Fast mod pow for RSA calculation. a^b % n

    Parameters

    • a: BigInteger
    • b: BigInteger
    • n: BigInteger

    Returns bigInt.BigInteger

  • getByteArray(integer: number | BigInteger, signed?: boolean): Buffer
  • Gets the arbitrary-length byte array corresponding to the given integer

    Parameters

    • integer: number | BigInteger
    • signed: boolean = false

    Returns Buffer

  • returnBigInt(num: string | number | bigint | BigInteger): BigInteger
  • getMinBigInt(arrayOfBigInts: (string | BigInteger)[]): bigInt.BigInteger
  • Helper function to return the smaller big int in an array

    Parameters

    • arrayOfBigInts: (string | BigInteger)[]

    Returns bigInt.BigInteger

  • getRandomInt(min: number, max: number): number
  • returns a random int from min (inclusive) and max (inclusive)

    Parameters

    • min: number
    • max: number

    Returns number

  • sleep(ms: number, isUnref?: boolean): Promise<unknown>
  • Sleeps a specified amount of time

    Parameters

    • ms: number

      time in milliseconds

    • isUnref: boolean = false

      make a timer unref'ed

    Returns Promise<unknown>

  • bufferXor(a: Buffer, b: Buffer): Buffer
  • Helper to export two buffers of same length

    Parameters

    • a: Buffer
    • b: Buffer

    Returns Buffer

  • crc32(buf: string | Buffer): number

Variables

_EntityType: { USER: number; CHAT: number; CHANNEL: number } = ...

Type declaration

  • USER: number
  • CHAT: number
  • CHANNEL: number

Generated using TypeDoc