This library lets you decrypt data from Telegram Passport. (It has no dependencies, too!)

## Usage

First, create a `TelegramPassport` object with your private key.

```js

constpassport=newTelegramPassport(yourPrivateKey)// The private key must be PEM-encoded

```

After this, you are ready to decrypt payloads. To decrypt a [`PassportData`](https://core.telegram.org/bots/api#passportdata) object from Telegram, use the `decrypt` method.

```js

// Obtain passportData through some means

vardecryptedData=passport.decrypt(passportData)

```

Here is an example of what the `decrypt` method will return for the scopes `personal_details`, `email`, `passport`, `identity_card`, and `utility_bill`.

```json

{

"payload":"bot_defined_payload",

"address":{

"data":{

"city":"Somecity",

"country_code":"US",

"post_code":"92069",

"state":"California",

"street_line1":"Address line 1",

"street_line2":""

}

},

"identity_card":{

"data":{

"document_no":"12345",

"expiry_date":"01.23.2021"

},

"front_side":{

"file":{

"file_id":"SOME_FILE_ID",

"file_date":1528299109

},

"secret":"BASE64_ENCODED_SECRET",

"hash":"BASE64_ENCODED_HASH"

},

"reverse_side":{

"file":{

"file_id":"SOME_FILE_ID",

"file_date":1528299109

},

"secret":"BASE64_ENCODED_SECRET",

"hash":"BASE64_ENCODED_HASH"

}

},

"personal_details":{

"data":{

"birth_date":"01.23.2000",

"country_code":"US",

"first_name":"Mark",

"gender":"male",

"last_name":"Zuckerberg",

"residence_country_code":"US"

}

},

"utility_bill":{

"files":[

{

"file":{

"file_id":"SOME_FILE_ID",

"file_date":1532621515

},

"secret":"BASE64_ENCODED_SECRET",

"hash":"BASE64_ENCODED_HASH"

},

{

"file":{

"file_id":"SOME_FILE_ID",

"file_date":1532621515

},

"secret":"BASE64_ENCODED_SECRET",

"hash":"BASE64_ENCODED_HASH"

}

]

}

}

```

## Handling Files

Files are returned differently than the [`PassportFile`](https://core.telegram.org/bots/api#passportfile) object. Every file returned by this library is in this format:

```json

{

"file":{

"file_id":"SOME_FILE_ID",

"file_date":1532621515

},

"secret":"BASE64_ENCODED_SECRET",

"hash":"BASE64_ENCODED_HASH"

}

```

`file` contains the original [`PassportFile`](https://core.telegram.org/bots/api#passportfile) object that was returned by the bot API, and `secret` / `hash` are the `secret` / `file_hash` from the [`FileCredentials`](https://core.telegram.org/passport#filecredentials), accordingly.

To download a file, call `getFile` like normal with the file ID. Once you get the file data, however, you must decrypt it. To do so, you can call the `decryptPassportCredentials` method:

```js

passport.decryptPassportCredentials(

fileData,// Should be a Buffer

Buffer.from(file.hash,"base64"),// It is assumed we are using our example object above