SKALE-2835 add api call to delete bls key

parent 17310b56
......@@ -113,6 +113,16 @@ void LevelDB::deleteKey(const string &_key) {
spdlog::debug("key deleted: {}",_key );
}
void LevelDB::deleteDkgPoly( const std::string& name ) {
std::lock_guard<std::recursive_mutex> lock(mutex);
auto status = db->Delete(writeOptions, Slice(name));
throwExceptionOnError(status);
spdlog::debug("key deleted: {}", name);
}
void LevelDB::writeByteArray(const char *_key, size_t _keyLen, const char *value,
......
......@@ -87,6 +87,8 @@ public:
void deleteKey(const string &_key);
void deleteDkgPoly( const std::string& name );
public:
......@@ -118,4 +120,4 @@ public:
#endif
\ No newline at end of file
#endif
......@@ -546,7 +546,7 @@ SGXWalletServer::createBLSPrivateKeyImpl(const string &_blsKeyName, const string
throw SGXException(INVALID_POLY_NAME, "Invalid polynomial name");
}
if (!checkName(_blsKeyName, "BLS_KEY")) {
throw SGXException(INVALID_POLY_NAME, "Invalid BLS key name");
throw SGXException(INVALID_BLS_NAME, "Invalid BLS key name");
}
if (!check_n_t(_t, _n)) {
throw SGXException(INVALID_DKG_PARAMS, "Invalid DKG parameters: n or t ");
......@@ -569,6 +569,7 @@ SGXWalletServer::createBLSPrivateKeyImpl(const string &_blsKeyName, const string
LevelDB::getLevelDb()->deleteDHDKGKey(name);
string shareG2_name = "shareG2_" + _polyName + "_" + to_string(i) + ":";
LevelDB::getLevelDb()->deleteKey(shareG2_name);
LevelDB::getLevelDb()->deleteDkgPoly(_polyName`);
}
} HANDLE_SGX_EXCEPTION(result)
......@@ -581,7 +582,7 @@ Json::Value SGXWalletServer::getBLSPublicKeyShareImpl(const string &_blsKeyName)
try {
if (!checkName(_blsKeyName, "BLS_KEY")) {
throw SGXException(INVALID_POLY_NAME, "Invalid BLSKey name");
throw SGXException(INVALID_BLS_NAME, "Invalid BLSKey name");
}
shared_ptr <string> encryptedKeyHex_ptr = readFromDb(_blsKeyName);
spdlog::debug("encr_bls_key_share is {}", *encryptedKeyHex_ptr);
......@@ -660,6 +661,19 @@ Json::Value SGXWalletServer::getServerVersionImpl() {
return result;
}
Json::Value SGXWalletServer::deleteBlsKeyImpl(const std::string& name) {
INIT_RESULT(result)
result["deleted"] = false;
try {
if (!checkName(_blsKeyName, "BLS_KEY")) {
throw SGXException(INVALID_BLS_NAME, "Invalid BLSKey name");
}
LevelDB::getLevelDb()->deleteBlsKey(name);
} HANDLE_SGX_EXCEPTION(result)
return result;
}
Json::Value SGXWalletServer::generateDKGPoly(const string &_polyName, int _t) {
WRITE_LOCK(m)
......@@ -763,6 +777,11 @@ Json::Value SGXWalletServer::getServerVersion() {
return getServerVersionImpl();
}
Json::Value SGXWalletServer::deleteBlsKey() {
READ_LOCK(m)
return deleteBlsKeyImpl();
}
shared_ptr <string> SGXWalletServer::readFromDb(const string &name, const string &prefix) {
auto dataStr = LevelDB::getLevelDb()->readString(prefix + name);
......
......@@ -103,6 +103,8 @@ public:
virtual Json::Value getServerVersion();
virtual Json::Value deleteBlsKey( const std::string& name );
static shared_ptr<string> readFromDb(const string &name, const string &prefix = "");
static void writeDataToDB(const string &Name, const string &value);
......@@ -154,6 +156,8 @@ public:
static Json::Value getServerVersionImpl();
static Json::Value deleteBlsKeyImpl(const std::string& name);
static void printDB();
static int initHttpServer();
......
......@@ -80,6 +80,7 @@ extern int autoconfirm;
#define INVALID_POLY_NAME -11
#define INVALID_DKG_PARAMS -12
#define INVALID_SECRET_SHARES_LENGTH -13
#define INVALID_BLS_NAME -15
#define CERT_REQUEST_DOES_NOT_EXIST -14
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment