npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@merqva/telegram-passport

v1.0.2

Published

Decrypt/Parse incoming Telegram Passport data

Downloads

9

Readme

Telegram Passport

Parse/Decrypt incoming Telegram Passport data

* Note: All the type definitions on this library are in compliance with those defined in the Telegram API specification

What does this library do?

Provided your Bot's Private Key, this library will:

What doesn't this library do?

  • Get the encrypted files corresponding to the requested fields* Download the encrypted files using the getFile API endpoint, then use the decryptData method to decrypt them

Usage

  • First, create a new instance of the TelegramPassport class
const telegramPassport = new TelegramPassport("<bot_private_key>");
  • Parse and decryp de data of all the elements shared with the bot
const data = telegramPassport.decryptPassportData(
    update.message.passport_data
);

// the nonce is retuned within the RequestedFields object

const nonce = data.nonce;

* update is the object representing the incoming Update that was sent to the Bot

  • Decryting files
/*
get the data corresponding to the file you want to decryp
for example, the front side of the id card
*/

const id_frontSide = data.identity_card.front_side;

// download the file using the getFile API endpoint

...

// decryp the file

const file = telegramPassport.decryptData(
  downloaded_file_data,
  id_fronSide.secret,
  id_fronSide.file_hash,
);
  • Depending on the fields you requested, you might not need to process the whole PassportData object; for example, the "phone_number" and "email" fields are not encrypted. Thus, you only need to decrypt the credentials to obtain the nonce, then, you can get "phone_number" and "email" from passport_data.data
/*
in this case, data will look like this

data: [
  {
    "type": "phone_number",
    "phone_number": "XXXXXXXXXXX",
    "hash": "the_base64-encoded_hash",
  },
  {
    "type": "email",
    "email": "[email protected]",
    "hash": "the_base64-encoded_hash"
  },
]
*/

// decrypt the credentials

const credentials = telegramPassport.decryptPassportCredentials(
  update.message.passport_data.credentials,
);

* update is the object representing the incoming Update that was sent to the Bot

What can be inproved?

  • The type "handling" in the decryptData method* Need a TS guru that can give me a hand with that, go check the code

Found a bug?

Open an issue (PRs are welcome)

* be patient, I might be busy

Stay in touch