Access hash telegram что это

от admin

Telegram passport

Telegram Passport is a unified authorization method for services that require personal identification. Users can upload their documents once, then instantly share their data with services that require real-world ID (finance, ICOs, etc.). Telegram doesn’t have access to the users’ personal information thanks to end-to-end encryption.

This page describes the request flow that client apps must used to send the requested data to the service.

Overview

From the perspective of a service that requires real-world ID, the process looks like this:

  • A user presses “Log in with Telegram” on your website or in your app.
  • You request the data you need.
  • The user accepts your privacy policy and agrees to share their data.
  • The user’s Telegram app downloads and decrypts the data you requested from the end-to-end encrypted storage on Telegram.
  • If some of the data you requested is missing, the user can add it to their Telegram Passport at this point.
  • The user’s app encrypts the data with your public key and sends it to you.
  • You decrypt the data, check it for errors and re-request any missing or invalid information.
  • You sign the user up for your service. Tada!

See As a bot to see how to request passport data using a bot, through the MTProto API. Look at the Passport Manual to see how to request passport data using a bot, through the simplified bot API.

From the perspective of a user, the process looks something like this:

  • Your app receives an event/intent from one of the SDKs, or from a custom source.
  • The user accepts your privacy policy and agrees to share their data.
  • The user’s Telegram app downloads the data you requested from the end-to-end encrypted storage on Telegram.
  • If some of the data you requested is missing, the user can add it to their Telegram Passport at this point.
  • The user’s app encrypts the data with your public key and sends it to the service.
  • You sign the user up for your service. Tada!

See As a user to see how user client apps should send passport data to a service, through the MTProto API.

As a bot

A simplified version of this process can be used using the bot API, for more info see the Passport Manual.

Using the MTProto API, the process is pretty much the same, up until the actual API calls.

Note that all binary fields are in raw binary format, unlike in the bot API where they are base64-encoded

Setting Up Telegram Passport
Requesting Information
Receiving information

When the user confirms your request by pressing the «Authorize» button, the MTProto API sends an updateNewMessage from the user, with a messageService constructor, containing a messageActionSecureValuesSentMe constructor that contains the encrypted Telegram Passport data.

Decrypting data

To decrypt the received data, first, decrypt the credentials contained in secureCredentialsEncrypted.

Decrypt the credentials secret ( secret field in secureCredentialsEncrypted) using your private key (set OAEP padding option, e.g. OPENSSL_PKCS1_OAEP_PADDING in PHP)

Use this secret and the credentials hash ( hash field in secureCredentialsEncrypted) to calculate credentials_key and credentials_iv as described below:

Decrypt the credentials data ( data field in secureCredentialsEncrypted) by AES256-CBC using these credentials_key and credentials_iv. IMPORTANT: At this step, make sure that the credentials hash is equal to SHA256( credentials_data )

Credentials data is padded with 32 to 255 random padding bytes to make its length divisible by 16 bytes. The first byte contains the length of this padding (including this byte). Remove the padding to get the data.

Note that all hashes are raw binary data, not hexits

Credentials

The credentials are a JSON-serialized object, structured exactly as in the bot API ». Since decryption credentials are E2E encrypted, apps have to store the decryption credentials as JSON and not TL payloads.

The credentials are used as described in the Passport Manual to decrypt the files attached to the secureValue. In this case, the container for the E2E encrypted data is in TL, while the encrypted data itself is in JSON.

secureValue

The schema for the secureValue constructor defines the constructor that can be found in each field.

Name Type Description
type SecureValueType Secure passport value type
data flags.0?SecureData Encrypted Telegram Passport element data
front_side flags.1?SecureFile Encrypted passport file with the front side of the document
reverse_side flags.2?SecureFile Encrypted passport file with the reverse side of the document
selfie flags.3?SecureFile Encrypted passport file with a selfie of the user holding the document
translation flags.6?Vector<SecureFile> Array of encrypted passport files with translated versions of the provided documents
files flags.4?Vector<SecureFile> Array of encrypted passport files with photos the of the documents
plain_data flags.5?SecurePlainData Plaintext verified passport data
hash bytes Data hash

Here’s a list of possible SecureValueTypes, and the parameters that can be set/requested when using each type.

Type Allowed fields
secureValueTypeEmail plain_data
secureValueTypePhone plain_data
secureValueTypePersonalDetails data
secureValueTypePassport data , front_side , selfie , translation
secureValueTypeDriverLicense data , front_side , reverse_side , selfie , translation
secureValueTypeIdentityCard data , front_side , reverse_side , selfie , translation
secureValueTypeInternalPassport data , front_side , selfie , translation
secureValueTypeAddress data
secureValueTypeUtilityBill files , translation
secureValueTypeBankStatement files , translation
secureValueTypeRentalAgreement files , translation
secureValueTypePassportRegistration files , translation
secureValueTypeTemporaryRegistration files , translation
SecureData

Data is an encrypted and padded JSON-serialized object of one of the specified JSON types, depending on the chosen type.

Chosen type JSON object
secureValueTypePersonalDetails PersonalDetails
secureValueTypePassport IdDocumentData
secureValueTypeDriverLicense IdDocumentData
secureValueTypeIdentityCard IdDocumentData
secureValueTypeInternalPassport IdDocumentData
secureValueTypeAddress ResidentialAddress

DataCredentials extracted from the credentials can then be used to decrypt encrypted data from the data field in secureData. For more info on how to decrypt the data field, see the passport manual.

SecureFile

Files (JPG format when decrypted, max. 10 MB) are downloaded chunk by chunk as described in files », except that instead of generating an inputFileLocation, an inputFileLocation should be generated, instead.

  • The id field is the id of the secureFile
  • The access_hash field is the access_hash of the secureFile

FileCredentials extracted from the credentials can then be used to decrypt downloaded encrypted data. For more info on how to decrypt passport files, see the passport manual.

SecurePlainData

The email/phone is passed in plaintext using the respective SecurePlainData constructor. Emails and phone numbers sent using telegram passport are already verified as described in the passport manual.

Fixing errors

If the data you received contains errors, the bot can use the users.setSecureValueErrors method to inform the user and request information again. The user will not be able to resend the data, until all errors are fixed.

Descriptions of the method parameters can be found in the method’s documentation page ».

As a user

Receiving requests

The process starts when your app receives an event from one of the SDKs, or from a custom source.

URI format

The SDKs trigger a passport authorization request by opening the following deep links »:

With the following query string parameters:

Parameters Type Required Description
domain String Required only for resolve versions of the passport URI Always telegrampassport for Passport authorization requests.
bot_id Integer Yes Unique identifier for the bot. You can get it from bot token. For example, for the bot token 1234567:4TT8bAc8GHUspu3ERYn-KGcvsvGB9u_n4ddy , the bot id is 1234567 .
scope UriPassportScope Yes A more compact JSON-serialized object describing the data you want to request
public_key String Yes Public key of the bot
nonce String Yes Bot-specified nonce. Important: For security purposes it should be a cryptographically secure unique identifier of the request. In particular, it should be long enough and it should be generated using a cryptographically secure pseudorandom number generator. You should never accept credentials with the same nonce twice.
callback_url String Optional Supported by some Telegram clients, specifies a callback URL to open once the process is finished or canceled.
payload String Optional Deprecated parameter from Telegram Passport 1.0 that had the same function of the nonce parameter.
Services that still use a legacy version of the SDK may provide this parameter instead of the nonce .
In some cases, both the nonce and the payload parameters may be found in a URI, for backwards compatibility: in this case, the nonce parameter should always be used instead of payload .
UriPassportScope

This object represents the data to be requested.

Field Type Description
d Array of UriPassportScopeElement List of requested elements, each type may be used only once in the entire array of UriPassportScopeElement objects
v Integer Scope version, must be 1
UriPassportScopeElement

This object represents a requested element, should be one of:

    — use to request any one of the documents included in the scope. – use to request one particular document.

Passport document type identifiers are aliased with the following reduced type identifiers:

Full Alias
personal_details pd
passport pp
driver_license dl
identity_card ic
internal_passport ip
id_document idd
address ad
utility_bill ub
bank_statement bs
rental_agreement ra
passport_registration pr
temporary_registration tr
address_document add
phone_number pn
email em

You can use the special type «idd» as an alias for one of «pp», «dl», «ic» and the special type «add» as an alias for one of «ub», «bs», «ra».

UriPassportScopeElementOneOfSeveral

This object represents several elements one of which must be provided.

Field Type Description
_ Array of UriPassportScopeElementOne List of elements one of which must be provided; must contain either several of “pp”, “dl”, “ic”, “ip” or several of “ub”, “bs”, “ra”, “pr”, “tr”
s Boolean Optional. Use this parameter if you want to request a selfie with the document from this list that the user chooses to upload.
t Boolean Optional. Use this parameter if you want to request a translation of the document from this list that the user chooses to upload. Note: We suggest to only request translations after you have received a valid document that requires one.
UriPassportScopeElementOne

This object represents one particular element that must be provided. If no options are needed, String can be used instead of this object to specify the type of the element.

Field Type Description
_ String Element type. One of «pd», «pp», «dl», «ic», «ip», «ad», «ub», «bs», «ra», «pr», «tr», «pn», «em»
s Boolean Optional. Use this parameter if you want to request a selfie with the document as well. Available for «pp», «dl», «ic» and «ip»
t Boolean Optional. Use this parameter if you want to request a translation of the document as well. Available for «pp», «dl», «ic», «ip», «ub», «bs», «ra», «pr» and «tr». Note: We suggest to only request translations after you have received a valid document that requires one.
n Boolean Optional. Use this parameter to request the first, last and middle name of the user in the language of the user’s country of residence. Available for «pd»

You can also use the special type «idd» as an alias for one of «pp», «dl», «ic» and the special type «add» as an alias for one of «ub», «bs», «ra».

Setting up Telegram Passport

The next step for the client app is to request the user’s 2FA passport, and configure Telegram Passport/fetch and decrypt remotely saved Telegram Passport parameters as described in the Encryption article ».

Fetching the passport form

Then, the client app passes the bot ID, scope and public key from the passport authorization request to the Telegram servers using the account.getAuthorizationForm method.

The response will be an account.authorizationForm constructor, with info about the required document types, the URL of the service’s privacy policy, as well as info about the bot to which the form should be sent. If the form was already submitted at least once, the constructor will also contain a list of already submitted data, along with eventual errors.

The user should accept the privacy policy and proceed to fill in the required data, and the client should encrypt and upload it as described in the Encryption article ».

Submitting the passport form

Once the user finishes uploading the required documents and clicks on the submit button, the client calls account.acceptAuthorization, submitting the documents to the bot associated to the service.

  • As before, bot_id , scope and public_key are taken from the authorization request URI.
  • value_hashes is used by the server to choose which document of which type to send to the bot: the type field should be set to the document type, and the hash field should be set to the data_hash / file_hash generated when uploading encrypting the data ».
  • credentials contains the encrypted credentials required by the service to decrypt the sent E2E encrypted secure values: it is generated as described in Passport Credentials ».

Finally, the client opens the callback URL (if present).

Handling invalid forms

If any of the values of the submitted form are rejected by the service, the bot calls the appropriate method to set information about errors.

The user can find out about these errors directly from the service, or, if they decide to restart the process and resend the corrected data, directly from the authorization form ( errors field).

Telegram channel- how to get access_hash?

I try really hard to understand howto use Telegram api with telethon. I have some Channels in Telegram, where i want to delete older Messages. Using inputpeerchannel() i need channel_id (No Problem) and channel_hash. I cant findout howto get this channel_hash by channel_id. Thank you from germany

2 Answers 2

In order to find channel access_hash , you should resolve channel username. Original MTProto method contacts.resolveUsername#f93ccba3 gets @username and returns channel info including access_hash .

In telethon you need to invoke ResolveUsernameRequest to call the above original MTProto method. You may use this code to resolve username to access_hash :

Канал в Telegram — как получить access_hash?

Я очень стараюсь понять, как использовать Telegram api с телемарафоном. У меня есть несколько каналов в Telegram, где я хочу удалить старые сообщения. Используя inputpeerchannel (), мне нужны channel_id (без проблем) и channel_hash. Я не могу найти, как получить этот channel_hash по channel_id. Спасибо из германии

2 ответа

Чтобы найти канал access_hash , вы должны разрешить имя пользователя канала. Исходный метод MTProto contacts.resolveUsername#f93ccba3 получает @username и возвращает информацию о канале, включая access_hash .

В телемарафоне вам нужно вызвать ResolveUsernameRequest, чтобы вызвать указанный выше исходный метод MTProto. Вы можете использовать этот код для преобразования имени пользователя в access_hash :

Как получить access_hash, пользователя который написал в группу | telethon?

на стаковерфлоу вот чо пишут
4 пункт то что надо но там нет примера кода
не могу вьехать как это сделать помогите плез
Код Python:

There are 4 ways to get access hash:

From a Group
From username
From contact list
From chats message

So, if you have id only, there is no way to get access hash

я понимаю что код который отправляет сообщение должен выглядеть так
но где ацесс хэш взять я нэ понимаю

Читать:
Тихая установка программы как выполнять через cmd

Похожие статьи