forked from hyperledger-iroha/iroha-dco
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/iroha-cli-tests' into develop
- Loading branch information
Showing
14 changed files
with
427 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved. | ||
* http://soramitsu.co.jp | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <utility> | ||
#include "keys_manager_impl.hpp" | ||
#include <fstream> | ||
#include "common/types.hpp" | ||
|
||
namespace iroha_cli { | ||
|
||
KeysManagerImpl::KeysManagerImpl(std::string account_name) | ||
: account_name_(std::move(account_name)) {} | ||
|
||
nonstd::optional<iroha::ed25519::keypair_t> KeysManagerImpl::loadKeys() { | ||
// Try to load from local file | ||
std::ifstream priv_file(account_name_ + ".priv"); | ||
std::ifstream pub_file(account_name_ + ".pub"); | ||
if (not priv_file || not pub_file) { | ||
return nonstd::nullopt; | ||
} | ||
std::string client_pub_key_; | ||
std::string client_priv_key_; | ||
priv_file >> client_priv_key_; | ||
pub_file >> client_pub_key_; | ||
|
||
iroha::ed25519::keypair_t keypair; | ||
auto privkey = iroha::hex2bytes(client_priv_key_); | ||
std::copy(privkey.begin(), privkey.end(), keypair.privkey.begin()); | ||
auto pubkey = iroha::hex2bytes(client_pub_key_); | ||
std::copy(pubkey.begin(), pubkey.end(), keypair.pubkey.begin()); | ||
return keypair; | ||
} | ||
|
||
bool KeysManagerImpl::createKeys(std::string pass_phrase) { | ||
auto seed = iroha::create_seed(pass_phrase); | ||
auto key_pairs = iroha::create_keypair(seed); | ||
std::ifstream pb_file(account_name_ + ".pub"); | ||
std::ifstream pr_file(account_name_ + ".priv"); | ||
if (pb_file && pr_file) { | ||
return false; | ||
} | ||
// Save pubkey to file | ||
std::ofstream pub_file(account_name_ + ".pub"); | ||
if (not pub_file) { | ||
return false; | ||
} | ||
pub_file << key_pairs.pubkey.to_hexstring(); | ||
// Save privkey to file | ||
std::ofstream priv_file(account_name_ + ".priv"); | ||
if (not priv_file) { | ||
return false; | ||
} | ||
priv_file << key_pairs.privkey.to_hexstring(); | ||
return true; | ||
} | ||
|
||
} // namespace iroha_cli |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved. | ||
* http://soramitsu.co.jp | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef IROHA_CLI_KEYS_MANAGER_IMPL_HPP | ||
#define IROHA_CLI_KEYS_MANAGER_IMPL_HPP | ||
#include "../keys_manager.hpp" | ||
|
||
namespace iroha_cli { | ||
class KeysManagerImpl : public KeysManager { | ||
public: | ||
explicit KeysManagerImpl(std::string account_name); | ||
|
||
nonstd::optional<iroha::ed25519::keypair_t> loadKeys() override; | ||
|
||
bool createKeys(std::string pass_phrase) override; | ||
|
||
private: | ||
std::string account_name_; | ||
}; | ||
} // namespace iroha_cli | ||
#endif // IROHA_CLI_KEYS_MANAGER_IMPL_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved. | ||
* http://soramitsu.co.jp | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef IROHA_CLI_KEYS_MANAGER_HPP | ||
#define IROHA_CLI_KEYS_MANAGER_HPP | ||
|
||
#include <nonstd/optional.hpp> | ||
#include "crypto/crypto.hpp" | ||
|
||
namespace iroha_cli { | ||
|
||
class KeysManager { | ||
public: | ||
/** | ||
* Load keys associated with account | ||
* @param account_name | ||
* @return nullopt if no keypair found locally | ||
*/ | ||
virtual nonstd::optional<iroha::ed25519::keypair_t> loadKeys() = 0; | ||
|
||
/** | ||
* Create keys and associate with account | ||
* @param account_name | ||
* @param pass_phrase | ||
* @return false if create account failed | ||
*/ | ||
virtual bool createKeys(std::string pass_phrase) = 0; | ||
|
||
}; | ||
|
||
} // namepsace iroha_cli | ||
#endif // IROHA_CLI_KEYS_MANAGER_HPP |
Oops, something went wrong.