/*
This file is part of TON Blockchain Library.
TON Blockchain Library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
TON Blockchain Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with TON Blockchain Library. If not, see .
Copyright 2017-2020 Telegram Systems LLP
*/
#pragma once
#include "td/utils/Status.h"
#include "td/utils/SharedSlice.h"
#include "KeyValue.h"
#include
namespace tonlib {
struct DecryptedKey;
class KeyStorage {
public:
struct Key {
td::SecureString public_key;
td::SecureString secret;
};
struct InputKey {
Key key;
td::SecureString local_password;
};
struct ExportedKey {
std::vector mnemonic_words;
};
struct ExportedPemKey {
td::SecureString pem;
};
struct ExportedEncryptedKey {
td::SecureString data;
};
struct ExportedUnencryptedKey {
td::SecureString data;
};
struct PrivateKey {
td::SecureString private_key;
};
void set_key_value(std::shared_ptr kv);
td::Result create_new_key(td::Slice local_password, td::Slice key_password, td::Slice entropy);
td::Result export_key(InputKey input_key);
td::Result export_pem_key(InputKey input_key, td::Slice key_password);
td::Result export_encrypted_key(InputKey input_key, td::Slice key_password);
td::Result export_unencrypted_key(InputKey input_key);
td::Result change_local_password(InputKey input_key, td::Slice new_local_password);
td::Status delete_key(const Key& key);
td::Status delete_all_keys();
td::Result import_key(td::Slice local_password, td::Slice mnemonic_password, ExportedKey exported_key);
td::Result import_pem_key(td::Slice local_password, td::Slice key_password, ExportedPemKey exported_key);
td::Result import_encrypted_key(td::Slice local_password, td::Slice key_password,
ExportedEncryptedKey exported_key);
td::Result import_unencrypted_key(td::Slice local_password, ExportedUnencryptedKey exported_key);
td::Result load_private_key(InputKey input_key);
static PrivateKey fake_private_key();
static InputKey fake_input_key();
static bool is_fake_input_key(InputKey& input_key);
private:
std::shared_ptr kv_;
td::Result save_key(const DecryptedKey& mnemonic, td::Slice local_password);
td::Result export_decrypted_key(InputKey input_key);
};
} // namespace tonlib