Add support for TON wallet.

GitOrigin-RevId: 1f44858add8a08a774ff0360222adaba9e2b9242
This commit is contained in:
levlam 2019-09-27 00:21:16 +03:00
parent a2429d595c
commit f03d5d285a
11 changed files with 116 additions and 0 deletions

View File

@ -1824,6 +1824,13 @@ gameHighScore position:int32 user_id:int32 score:int32 = GameHighScore;
gameHighScores scores:vector<gameHighScore> = GameHighScores;
//@description Contains the response of a request to TON lite server @response The response
tonLiteServerResponse response:bytes = TonLiteServerResponse;
//@description Contains the salt to be used with locally stored password to access a local TON-based wallet @salt The salt
tonWalletPasswordSalt salt:bytes = TonWalletPasswordSalt;
//@class ChatEventAction @description Represents a chat event
//@description A message was edited @old_message The original message before the edit @new_message The message after it was edited
@ -3947,6 +3954,13 @@ sendCustomRequest method:string parameters:string = CustomRequestResult;
answerCustomQuery custom_query_id:int64 data:string = Ok;
//@description Sends a request to TON lite server through Telegram servers @request The request
sendTonLiteServerRequest request:bytes = TonLiteServerResponse;
//@description Returns a salt to be used with locally stored password to access a local TON-based wallet
getTonWalletPasswordSalt = TonWalletPasswordSalt;
//@description Succeeds after a specified amount of time has passed. Can be called before authorization. Can be called before initialization @seconds Number of seconds before the function returns
setAlarm seconds:double = Ok;

Binary file not shown.

View File

@ -1011,6 +1011,10 @@ emojiURL#a575739d url:string = EmojiURL;
emojiLanguage#b3fb5361 lang_code:string = EmojiLanguage;
wallet.liteResponse#764386d7 response:bytes = wallet.LiteResponse;
wallet.secretSalt#dd484d64 salt:bytes = wallet.KeySecretSalt;
fileLocationToBeDeprecated#bc7fc6cd volume_id:long local_id:int = FileLocation;
---functions---
@ -1325,3 +1329,6 @@ langpack.getStrings#efea3803 lang_pack:string lang_code:string keys:Vector<strin
langpack.getDifference#cd984aa5 lang_pack:string lang_code:string from_version:int = LangPackDifference;
langpack.getLanguages#42c6978f lang_pack:string = Vector<LangPackLanguage>;
langpack.getLanguage#6a596502 lang_pack:string lang_code:string = LangPackLanguage;
wallet.sendLiteRequest#e2c9d33e body:bytes = wallet.LiteResponse;
wallet.getKeySecretSalt#b57f346 revoke:Bool = wallet.KeySecretSalt;

Binary file not shown.

View File

@ -726,6 +726,40 @@ void PasswordManager::drop_cached_secret() {
secret_ = optional<secure_storage::Secret>();
}
void PasswordManager::get_ton_wallet_password_salt(Promise<td_api::object_ptr<td_api::tonWalletPasswordSalt>> promise) {
if (!ton_wallet_password_salt_.empty()) {
return promise.set_value(td_api::make_object<td_api::tonWalletPasswordSalt>(ton_wallet_password_salt_));
}
get_ton_wallet_password_salt_queries_.push_back(std::move(promise));
if (get_ton_wallet_password_salt_queries_.size() == 1) {
send_with_promise(G()->net_query_creator().create(create_storer(telegram_api::wallet_getKeySecretSalt())),
PromiseCreator::lambda([actor_id = actor_id(this)](Result<NetQueryPtr> r_query) mutable {
auto r_result = fetch_result<telegram_api::wallet_getKeySecretSalt>(std::move(r_query));
send_closure(actor_id, &PasswordManager::on_get_ton_wallet_password_salt, std::move(r_result));
}));
}
}
void PasswordManager::on_get_ton_wallet_password_salt(
Result<telegram_api::object_ptr<telegram_api::wallet_secretSalt>> result) {
auto promises = std::move(get_ton_wallet_password_salt_queries_);
reset_to_empty(get_ton_wallet_password_salt_queries_);
CHECK(!promises.empty());
if (result.is_ok()) {
ton_wallet_password_salt_ = result.ok()->salt_.as_slice().str();
for (auto &promise : promises) {
promise.set_value(td_api::make_object<td_api::tonWalletPasswordSalt>(ton_wallet_password_salt_));
}
} else {
for (auto &promise : promises) {
promise.set_error(result.error().clone());
}
}
}
void PasswordManager::timeout_expired() {
if (Time::now() >= secret_expire_date_) {
drop_cached_secret();

View File

@ -87,6 +87,8 @@ class PasswordManager : public NetQueryCallback {
static TempPasswordState get_temp_password_state_sync();
void get_ton_wallet_password_salt(Promise<td_api::object_ptr<td_api::tonWalletPasswordSalt>> promise);
private:
static constexpr size_t MIN_NEW_SALT_SIZE = 8;
static constexpr size_t MIN_NEW_SECURE_SALT_SIZE = 8;
@ -158,6 +160,9 @@ class PasswordManager : public NetQueryCallback {
int32 last_code_length_ = 0;
string ton_wallet_password_salt_;
vector<Promise<td_api::object_ptr<td_api::tonWalletPasswordSalt>>> get_ton_wallet_password_salt_queries_;
static Result<secure_storage::Secret> decrypt_secure_secret(
Slice password, tl_object_ptr<telegram_api::SecurePasswordKdfAlgo> algo_ptr, Slice secret, int64 secret_id);
@ -184,6 +189,8 @@ class PasswordManager : public NetQueryCallback {
Promise<TempPasswordState> promise);
void on_finish_create_temp_password(Result<TempPasswordState> result, bool dummy);
void on_get_ton_wallet_password_salt(Result<telegram_api::object_ptr<telegram_api::wallet_secretSalt>> result);
void on_result(NetQueryPtr query) override;
void start_up() override;

View File

@ -487,6 +487,34 @@ class ClearSavedInfoQuery : public Td::ResultHandler {
}
};
class SendLiteRequestQuery : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::tonLiteServerResponse>> promise_;
public:
explicit SendLiteRequestQuery(Promise<td_api::object_ptr<td_api::tonLiteServerResponse>> &&promise)
: promise_(std::move(promise)) {
}
void send(BufferSlice request) {
send_query(
G()->net_query_creator().create(create_storer(telegram_api::wallet_sendLiteRequest(std::move(request)))));
}
void on_result(uint64 id, BufferSlice packet) override {
auto result_ptr = fetch_result<telegram_api::wallet_sendLiteRequest>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
}
auto response = result_ptr.move_as_ok();
promise_.set_value(td_api::make_object<td_api::tonLiteServerResponse>(response->response_.as_slice().str()));
}
void on_error(uint64 id, Status status) override {
promise_.set_error(std::move(status));
}
};
bool operator==(const LabeledPricePart &lhs, const LabeledPricePart &rhs) {
return lhs.label == rhs.label && lhs.amount == rhs.amount;
}
@ -869,4 +897,8 @@ void delete_saved_credentials(Promise<Unit> &&promise) {
G()->td().get_actor_unsafe()->create_handler<ClearSavedInfoQuery>(std::move(promise))->send(true, false);
}
void send_ton_lite_server_request(Slice request, Promise<td_api::object_ptr<td_api::tonLiteServerResponse>> &&promise) {
G()->td().get_actor_unsafe()->create_handler<SendLiteRequestQuery>(std::move(promise))->send(BufferSlice{request});
}
} // namespace td

View File

@ -154,4 +154,6 @@ void delete_saved_order_info(Promise<Unit> &&promise);
void delete_saved_credentials(Promise<Unit> &&promise);
void send_ton_lite_server_request(Slice request, Promise<td_api::object_ptr<td_api::tonLiteServerResponse>> &&promise);
} // namespace td

View File

@ -7127,6 +7127,18 @@ void Td::on_request(uint64 id, const td_api::deleteSavedCredentials &request) {
delete_saved_credentials(std::move(promise));
}
void Td::on_request(uint64 id, const td_api::sendTonLiteServerRequest &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
send_ton_lite_server_request(request.request_, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getTonWalletPasswordSalt &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
send_closure(password_manager_, &PasswordManager::get_ton_wallet_password_salt, std::move(promise));
}
void Td::on_request(uint64 id, td_api::getPassportElement &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.password_);

View File

@ -898,6 +898,10 @@ class Td final : public NetQueryCallback {
void on_request(uint64 id, const td_api::deleteSavedCredentials &request);
void on_request(uint64 id, const td_api::sendTonLiteServerRequest &request);
void on_request(uint64 id, const td_api::getTonWalletPasswordSalt &request);
void on_request(uint64 id, td_api::getPassportElement &request);
void on_request(uint64 id, td_api::getAllPassportElements &request);

View File

@ -1529,6 +1529,10 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::deleteSavedOrderInfo>());
} else if (op == "dsc") {
send_request(td_api::make_object<td_api::deleteSavedCredentials>());
} else if (op == "stlsr") {
send_request(td_api::make_object<td_api::sendTonLiteServerRequest>());
} else if (op == "gtwps") {
send_request(td_api::make_object<td_api::getTonWalletPasswordSalt>());
} else if (op == "gpr") {
send_request(td_api::make_object<td_api::getUserPrivacySettingRules>(get_user_privacy_setting(args)));
} else if (op == "spr") {