Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MTProtoState

Hierarchy

  • MTProtoState

Index

Properties

timeOffset: number
salt: BigInteger
_sequence: number

Constructors

  • telethon.network.mtprotosender.MTProtoSender needs to hold a state in order to be able to encrypt and decrypt incoming/outgoing messages, as well as generating the message IDs. Instances of this class hold together all the required information.

    It doesn't make sense to use telethon.sessions.abstract.Session for the sender because the sender should not be concerned about storing this information to disk, as one may create as many senders as they desire to any other data center, or some CDN. Using the same session for all these is not a good idea as each need their own authkey, and the concept of "copying" sessions with the unnecessary entities or updates state for these connections doesn't make sense.

    While it would be possible to have a MTProtoPlainState that does no encryption so that it was usable through the MTProtoLayer and thus avoid the need for a MTProtoPlainSender, the MTProtoLayer is more focused to efficiency and this state is also more advanced (since it supports gzipping and invoking after other message IDs). There are too many methods that would be needed to make it convenient to use for the authentication process, at which point the MTProtoPlainSender is better

    Parameters

    • Optional authKey: AuthKey
    • Optional loggers: any
    • securityChecks: boolean = true

    Returns MTProtoState

Methods

  • reset(): void
  • updateMessageId(message: any): void
  • _calcKey(authKey: Buffer, msgKey: Buffer, client: boolean): Promise<{ key: Buffer; iv: Buffer }>
  • Calculate the key based on Telegram guidelines, specifying whether it's the client or not

    Parameters

    • authKey: Buffer
    • msgKey: Buffer
    • client: boolean

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

  • writeDataAsMessage(buffer: BinaryWriter, data: Buffer, contentRelated: boolean, afterId?: BigInteger): Promise<BigInteger>
  • Writes a message containing the given data into buffer. Returns the message id.

    Parameters

    • buffer: BinaryWriter
    • data: Buffer
    • contentRelated: boolean
    • Optional afterId: BigInteger

    Returns Promise<BigInteger>

  • encryptMessageData(data: Buffer): Promise<Buffer>
  • Encrypts the given message data using the current authorization key following MTProto 2.0 guidelines core.telegram.org/mtproto/description.

    Parameters

    • data: Buffer

    Returns Promise<Buffer>

  • decryptMessageData(body: Buffer): Promise<TLMessage>
  • updateTimeOffset(correctMsgId: BigInteger): number
  • Updates the time offset to the correct one given a known valid message ID.

    Parameters

    • correctMsgId: BigInteger

    Returns number

Generated using TypeDoc