Skip to content

miniproto.auth.bootstrap.ensure_auth_key

ensure_auth_key(config: ClientConfig, storage: SessionStorage) -> None

Ensure that storage contains a usable MTProto key and DC options.

Existing keys are preserved. When no key is present, this performs Telegram’s unencrypted authorization-key exchange, then atomically stores its key, salt, server-time offset, and resolved data-center options.

Parameters:

  • config (ClientConfig) – Client configuration, including target DC and test-mode selection.
  • storage (SessionStorage) – Mutable session store to inspect and update.

Raises:

  • ValueError – If the configured DC or Telegram key-exchange response is invalid.
  • ConnectionError – If the unencrypted exchange receives an unexpected quick ACK.