Skip to content

Commit

Permalink
531: Add GenerateKeyExample
Browse files Browse the repository at this point in the history
Signed-off-by: Rob Walworth <[email protected]>
  • Loading branch information
rwalworth authored Oct 16, 2023
1 parent ab974ac commit d242542
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions sdk/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ set(DELETE_ACCOUNT_EXAMPLE_NAME ${PROJECT_NAME}-delete-account-example)
set(DELETE_FILE_EXAMPLE_NAME ${PROJECT_NAME}-delete-file-example)
set(EXEMPT_CUSTOM_FEES_EXAMPLE_NAME ${PROJECT_NAME}-exempt-custom-fees-example)
set(FILE_APPEND_CHUNKED_EXAMPLE_NAME ${PROJECT_NAME}-file-append-chunked-example)
set(GENERATE_KEY_EXAMPLE_NAME ${PROJECT_NAME}-generate-key-example)
set(GENERATE_PRIVATE_KEY_FROM_MNEMONIC_EXAMPLE_NAME ${PROJECT_NAME}-generate-private-key-from-mnemonic-example)
set(GET_ACCOUNT_BALANCE_EXAMPLE_NAME ${PROJECT_NAME}-get-account-balance-example)
set(GET_ADDRESS_BOOK_EXAMPLE_NAME ${PROJECT_NAME}-get-address-book-example)
Expand Down Expand Up @@ -52,6 +53,7 @@ add_executable(${DELETE_ACCOUNT_EXAMPLE_NAME} DeleteAccountExample.cc)
add_executable(${DELETE_FILE_EXAMPLE_NAME} DeleteFileExample.cc)
add_executable(${EXEMPT_CUSTOM_FEES_EXAMPLE_NAME} ExemptCustomFeesExample.cc)
add_executable(${FILE_APPEND_CHUNKED_EXAMPLE_NAME} FileAppendChunkedExample.cc)
add_executable(${GENERATE_KEY_EXAMPLE_NAME} GenerateKeyExample.cc)
add_executable(${GENERATE_PRIVATE_KEY_FROM_MNEMONIC_EXAMPLE_NAME} GeneratePrivateKeyFromMnemonic.cc)
add_executable(${GET_ACCOUNT_BALANCE_EXAMPLE_NAME} GetAccountBalanceExample.cc)
add_executable(${GET_ADDRESS_BOOK_EXAMPLE_NAME} GetAddressBookExample.cc)
Expand Down Expand Up @@ -107,6 +109,7 @@ target_link_libraries(${DELETE_ACCOUNT_EXAMPLE_NAME} PUBLIC ${PROJECT_NAME})
target_link_libraries(${DELETE_FILE_EXAMPLE_NAME} PUBLIC ${PROJECT_NAME})
target_link_libraries(${EXEMPT_CUSTOM_FEES_EXAMPLE_NAME} PUBLIC ${PROJECT_NAME})
target_link_libraries(${FILE_APPEND_CHUNKED_EXAMPLE_NAME} PUBLIC ${PROJECT_NAME})
target_link_libraries(${GENERATE_KEY_EXAMPLE_NAME} PUBLIC ${PROJECT_NAME})
target_link_libraries(${GENERATE_PRIVATE_KEY_FROM_MNEMONIC_EXAMPLE_NAME} PUBLIC ${PROJECT_NAME})
target_link_libraries(${GET_ACCOUNT_BALANCE_EXAMPLE_NAME} PUBLIC ${PROJECT_NAME})
target_link_libraries(${GET_ADDRESS_BOOK_EXAMPLE_NAME} PUBLIC ${PROJECT_NAME})
Expand Down Expand Up @@ -145,6 +148,7 @@ install(TARGETS
${DELETE_FILE_EXAMPLE_NAME}
${EXEMPT_CUSTOM_FEES_EXAMPLE_NAME}
${FILE_APPEND_CHUNKED_EXAMPLE_NAME}
${GENERATE_KEY_EXAMPLE_NAME}
${GENERATE_PRIVATE_KEY_FROM_MNEMONIC_EXAMPLE_NAME}
${GET_ACCOUNT_BALANCE_EXAMPLE_NAME}
${GET_ADDRESS_BOOK_EXAMPLE_NAME}
Expand Down
40 changes: 40 additions & 0 deletions sdk/examples/GenerateKeyExample.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*-
*
* Hedera C++ SDK
*
* Copyright (C) 2020 - 2023 Hedera Hashgraph, LLC
*
* 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 "ECDSAsecp256k1PrivateKey.h"
#include "ED25519PrivateKey.h"
#include "PrivateKey.h"
#include "PublicKey.h"

#include <iostream>

using namespace Hedera;

int main(int argc, char** argv)
{
const std::unique_ptr<PrivateKey> ed25519Key = ED25519PrivateKey::generatePrivateKey();
const std::unique_ptr<PrivateKey> ecdsaKey = ECDSAsecp256k1PrivateKey::generatePrivateKey();

std::cout << "Generated ED25519PrivateKey: " << ed25519Key->toStringRaw() << std::endl;
std::cout << "Generated ED25519PublicKey: " << ed25519Key->getPublicKey()->toStringRaw() << std::endl;
std::cout << "Generated ECDSAsecp256k1PrivateKey: " << ecdsaKey->toStringRaw() << std::endl;
std::cout << "Generated ECDSAsecp256k1PublicKey: " << ecdsaKey->getPublicKey()->toStringRaw() << std::endl;

return 0;
}

0 comments on commit d242542

Please sign in to comment.