Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mtproto/core

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mtproto/core

Telegram API (MTProto) client library for browser

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.3K
decreased by-10.12%
Maintainers
1
Weekly downloads
 
Created
Source

@mtproto/core

NPM Travis

Telegram API (MTProto) client library for browser

  • Actual. 108 layer in the API scheme
  • Fast. Uses WebSocket to work with the network
  • Easy. Cryptography is hidden. Just make requests to the API
  • 2FA. Use the library's built-in function to calculate 2FA parameters

Install

yarn add @mtproto/core -E

Quick start

You need api_id and api_hash. If you do not have them yet, then get them according to the official instructions: creating your Telegram application.

const MTProto = require('@mtproto/core');

// 1. Create an instance
const mtproto = new MTProto({
  api_id: YOU_API_ID,
  api_hash: YOU_API_HASH,

  // Use test server
  test: true,
});

// 2. Log in using phone number
// https://core.telegram.org/api/auth#test-phone-numbers
const phone = '+9996621111';
const code = '22222';

mtproto
  .call('auth.sendCode', {
    phone_number: phone,
    settings: {
      _: 'codeSettings',
    },
  })
  .then(result => {
    mtproto
      .call('auth.signIn', {
        phone_code: code,
        phone_number: phone,
        phone_code_hash: result.phone_code_hash,
      })
      .then(result => {
        console.log(`auth.signIn[result]:`, result);
      })
      .catch(error => {
        if (error.error_message === 'SESSION_PASSWORD_NEEDED') {
          // Need use 2FA
        }
      });
  });

2FA (Two-factor authentication)

const { getSRPParams } = require('@mtproto/core/utils');

const password = 'YOU_PASSWORD';

mtproto
  .call('account.getPassword')
  .then(async result => {
    const { srp_id, current_algo, srp_B } = result;
    const { salt1, salt2, g, p } = current_algo;

    const { A, M1 } = await getSRPParams({
      g,
      p,
      salt1,
      salt2,
      gB: srp_B,
      password,
    });

    return mtproto.call('auth.checkPassword', {
      password: {
        _: 'inputCheckPasswordSRP',
        srp_id,
        A,
        M1,
      },
    });
  })
  .then(result => {
    console.log(`auth.checkPassword[result]:`, result);
  });

Keywords

FAQs

Package last updated on 22 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc