ZaStoGram_desktop/Telegram/SourceFiles/wallet/wallet_phrase_shares.h
John Preston a2420539a3 Pad the wallet backup seed to the server's field length
Task: 2026/08/30/enable-and-disable-encrypted-backup
2026-10-08 22:23:54 +04:00

47 lines
1.7 KiB
C++

/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
namespace TdE2E {
class TemporaryKeyPair;
} // namespace TdE2E
namespace Wallet::PhraseShares {
inline constexpr auto kPublicKeySize = 32;
// The server stores every seed as a fixed 215-byte space-padded field,
// so a shorter phrase is right-padded with spaces to fill it.
inline constexpr auto kSeedLength = 215;
inline constexpr auto kDecryptedKeyPartId = uint32(0x8b90dd08);
// Opens one holder part: the sender's public key, then the ciphertext of a
// TL-serialized mnemonic.decryptedKeyPart whose share string is returned.
[[nodiscard]] std::optional<QByteArray> DecryptShare(
const TdE2E::TemporaryKeyPair &keys,
const QByteArray &data);
[[nodiscard]] std::optional<QByteArray> CombineShares(
const std::vector<QByteArray> &shares);
// The words joined by single spaces, UTF-8, right-padded with spaces to
// kSeedLength bytes: the seed that gets split. Empty if the join is longer.
[[nodiscard]] QByteArray SeedFromWords(const std::vector<QString> &words);
// Returns count shares of the seed's length whose XOR is the seed; all but
// the last one are filled from the CSPRNG.
[[nodiscard]] std::vector<QByteArray> SplitSeed(
const QByteArray &seed,
int count);
// Seals one holder part: a 32-byte ephemeral public key, then the ciphertext
// of a TL-serialized mnemonic.decryptedKeyPart carrying the share.
[[nodiscard]] std::optional<QByteArray> EncryptShare(
const QByteArray &holderPublicKey,
const QByteArray &share);
} // namespace Wallet::PhraseShares