GramJS

account.SaveSecureValue

Securely save Telegram Passport document, for more info see the passport docs »

Example

const { Api, TelegramClient } = require("telegram");
const { StringSession } = require("telegram/sessions");

const session = new StringSession(""); // You should put your string session here
const client = new TelegramClient(session, apiId, apiHash, {});

(async function run() {
  await client.connect(); // This assumes you have already authenticated with .start()

  const result = await client.invoke(
    new Api.account.SaveSecureValue({
      value: new Api.InputSecureValue({
        type: new Api.SecureValueTypePersonalDetails({}),
        data: new Api.SecureData({
          data: Buffer.from("arbitrary data here"),
          dataHash: Buffer.from("arbitrary data here"),
          secret: Buffer.from("arbitrary data here"),
        }),
        frontSide: new Api.InputSecureFileUploaded({
          id: BigInt("-4156887774564"),
          parts: 43,
          md5Checksum: "some string here",
          fileHash: Buffer.from("arbitrary data here"),
          secret: Buffer.from("arbitrary data here"),
        }),
        reverseSide: new Api.InputSecureFileUploaded({
          id: BigInt("-4156887774564"),
          parts: 43,
          md5Checksum: "some string here",
          fileHash: Buffer.from("arbitrary data here"),
          secret: Buffer.from("arbitrary data here"),
        }),
        selfie: new Api.InputSecureFileUploaded({
          id: BigInt("-4156887774564"),
          parts: 43,
          md5Checksum: "some string here",
          fileHash: Buffer.from("arbitrary data here"),
          secret: Buffer.from("arbitrary data here"),
        }),
        translation: [
          new Api.InputSecureFileUploaded({
            id: BigInt("-4156887774564"),
            parts: 43,
            md5Checksum: "some string here",
            fileHash: Buffer.from("arbitrary data here"),
            secret: Buffer.from("arbitrary data here"),
          }),
        ],
        files: [
          new Api.InputSecureFileUploaded({
            id: BigInt("-4156887774564"),
            parts: 43,
            md5Checksum: "some string here",
            fileHash: Buffer.from("arbitrary data here"),
            secret: Buffer.from("arbitrary data here"),
          }),
        ],
        plainData: new Api.SecurePlainPhone({
          phone: "some string here",
        }),
      }),
      secureSecretId: BigInt("-4156887774564"),
    })
  );
  console.log(result); // prints the result
})();
import { Api, TelegramClient } from "telegram";
import { StringSession } from "telegram/sessions";

const session = new StringSession(""); // You should put your string session here
const client = new TelegramClient(session, apiId, apiHash, {});

(async function run() {
  await client.connect(); // This assumes you have already authenticated with .start()

  const result: Api.SecureValue = await client.invoke(
    new Api.account.SaveSecureValue({
      value: new Api.InputSecureValue({
        type: new Api.SecureValueTypePersonalDetails({}),
        data: new Api.SecureData({
          data: Buffer.from("arbitrary data here"),
          dataHash: Buffer.from("arbitrary data here"),
          secret: Buffer.from("arbitrary data here"),
        }),
        frontSide: new Api.InputSecureFileUploaded({
          id: BigInt("-4156887774564"),
          parts: 43,
          md5Checksum: "some string here",
          fileHash: Buffer.from("arbitrary data here"),
          secret: Buffer.from("arbitrary data here"),
        }),
        reverseSide: new Api.InputSecureFileUploaded({
          id: BigInt("-4156887774564"),
          parts: 43,
          md5Checksum: "some string here",
          fileHash: Buffer.from("arbitrary data here"),
          secret: Buffer.from("arbitrary data here"),
        }),
        selfie: new Api.InputSecureFileUploaded({
          id: BigInt("-4156887774564"),
          parts: 43,
          md5Checksum: "some string here",
          fileHash: Buffer.from("arbitrary data here"),
          secret: Buffer.from("arbitrary data here"),
        }),
        translation: [
          new Api.InputSecureFileUploaded({
            id: BigInt("-4156887774564"),
            parts: 43,
            md5Checksum: "some string here",
            fileHash: Buffer.from("arbitrary data here"),
            secret: Buffer.from("arbitrary data here"),
          }),
        ],
        files: [
          new Api.InputSecureFileUploaded({
            id: BigInt("-4156887774564"),
            parts: 43,
            md5Checksum: "some string here",
            fileHash: Buffer.from("arbitrary data here"),
            secret: Buffer.from("arbitrary data here"),
          }),
        ],
        plainData: new Api.SecurePlainPhone({
          phone: "some string here",
        }),
      }),
      secureSecretId: BigInt("-4156887774564"),
    })
  );
  console.log(result); // prints the result
})();

Parameters

NameTypeDescription
valueInputSecureValueSecure value, for more info see the passport docs »
secureSecretIdlongPassport secret hash, for more info see the passport docs »

Result

SecureValue

Possible errors

CodeTypeDescription

Can bots use this method?

No

Telegram Passport Encryption Details

Telegram Passport Manual