9#include "td/e2e/e2e_errors.h"
40 Result(
const T &value) : data_(value) {
42 Result(T &&value) : data_(std::move(value)) {
51 Result(td::Status &&status);
55 return std::holds_alternative<T>(data_);
59 bool is_error()
const {
60 return std::holds_alternative<Error>(data_);
64 return std::get<T>(data_);
66 const T &value()
const {
67 return std::get<T>(data_);
71 return std::get<Error>(data_);
73 const Error &error()
const {
74 return std::get<Error>(data_);
78 std::variant<T, Error> data_;
85using Int256 = std::array<unsigned char, 32>;
86using Int512 = std::array<unsigned char, 64>;
88using PublicKey = std::string;
89using HandshakeId = std::int64_t;
90using LoginId = std::int64_t;
91using UserId = std::int64_t;
92using AnyKeyId = std::int64_t;
93using PrivateKeyId = std::int64_t;
94using PublicKeyId = std::int64_t;
95using SymmetricKeyId = std::int64_t;
96using Bytes = std::string;
97using SecureBytes = std::string;
98using Slice = std::string_view;
99using SecureSlice = std::string_view;
103 std::vector<std::string> encrypted_headers;
104 std::string encrypted_message;
116Result<Bytes> key_to_encrypted_private_key(PrivateKeyId key_id, SymmetricKeyId secret_id);
117Result<PrivateKeyId> key_from_encrypted_private_key(Slice encrypted_key, SymmetricKeyId secret_id);
128Result<Bytes> key_to_encrypted_private_key_internal(PrivateKeyId key_id, SymmetricKeyId secret_id);
129Result<PrivateKeyId> key_from_encrypted_private_key_internal(Slice encrypted_key, SymmetricKeyId secret_id);
132 SecureSlice message);
135 const std::vector<SymmetricKeyId> &encrypt_key_ids,
136 Slice encrypted_header, Slice encrypted_message);
137Result<SecureBytes> decrypt_message_for_many(SymmetricKeyId key_id, Slice encrypted_header, Slice encrypted_message);
138Result<Bytes> encrypt_message_for_one(SymmetricKeyId key_id, SecureSlice message);
139Result<SecureBytes> decrypt_message_for_one(SymmetricKeyId key_id, Slice encrypted_message);
158Result<HandshakeId> handshake_create_for_bob(UserId bob_user_id, PrivateKeyId bob_private_key_id);
159Result<HandshakeId> handshake_create_for_alice(UserId alice_user_id, PrivateKeyId alice_private_key_id,
160 UserId bob_user_id,
const PublicKey &bob_public_key, Slice start);
162Result<Bytes> handshake_bob_send_start(HandshakeId bob_handshake_id);
163Result<Bytes> handshake_alice_send_accept(HandshakeId alice_handshake_id);
164Result<Bytes> handshake_bob_receive_accept_send_finish(HandshakeId bob_handshake_id, UserId alice_id,
165 const PublicKey &alice_public_key, Slice accept);
166Result<Ok> handshake_alice_receive_finish(HandshakeId alice_handshake_id, Slice finish);
168Result<Ok> handshake_destroy(HandshakeId handshake_id);
177Result<Bytes> login_create_for_alice(UserId alice_user_id, PrivateKeyId alice_private_key_id, Slice start);
178Result<PrivateKeyId> login_finish_for_bob(LoginId bob_login_id, UserId alice_user_id,
const PublicKey &alice_public_key,
193 enum Source { Self, Server,
Contact };
195 std::uint32_t timestamp;
198 Entry() : source(Self), timestamp(0), value() {
200 Entry(Source source, std::uint32_t timestamp, T &&value)
201 : source(source), timestamp(timestamp), value(std::move(value)) {
208 std::uint32_t timestamp{0};
213 std::string first_name;
214 std::string last_name;
218 std::string phone_number;
222 std::optional<Int256> self_nonce;
223 std::optional<Int256> contact_nonce_hash;
224 std::optional<Int256> contact_nonce;
228 enum State { Unknown,
Contact, NotContact };
229 State state{Unknown};
240 std::uint32_t generation{0};
243 PublicKeyId public_key{};
246 std::optional<Entry<UserId>> o_user_id;
247 std::optional<Entry<Name>> o_name;
248 std::optional<Entry<PhoneNumber>> o_phone_number;
260using StorageId = std::int64_t;
261using UpdateId = std::int64_t;
264 std::string next_suggested_block;
265 std::vector<std::string> required_proofs;
268 std::vector<std::pair<PublicKeyId, std::optional<Contact>>> updates;
272Result<Ok> storage_destroy(StorageId storage_id);
285Result<Ok> storage_blockchain_add_proof(StorageId storage_id, Slice proof,
const std::vector<std::string> &keys);
289using CallId = std::int64_t;
290using CallChannelId = std::int32_t;
293 PublicKeyId public_key_id{};
299 std::vector<CallParticipant> participants;
303Result<Bytes> call_create_self_add_block(PrivateKeyId private_key_id, Slice previous_block,
305Result<CallId> call_create(UserId user_id, PrivateKeyId private_key_id, Slice last_block);
312Result<Bytes> call_encrypt(CallId call_id, CallChannelId channel_id, SecureSlice message,
313 size_t unencrypted_prefix_size);
314Result<SecureBytes> call_decrypt(CallId call_id, UserId user_id, CallChannelId channel_id, Slice message);
323 std::optional<Bytes> emoji_hash;
336 std::vector<std::string> words;