diff --git a/CMakeLists.txt b/CMakeLists.txt index c6604e2..8fa265e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,13 +12,19 @@ find_package(OpenSSL 1.1 REQUIRED) include_directories( ${OPENSSL_INCLUDE_DIR} ) +if (${CMAKE_SYSTEM_NAME} STREQUAL Emscripten) + set (src_main src/wasm.cpp) +else() + set (src_main src/main.cpp) +endif() + add_executable( ${CMAKE_PROJECT_NAME} src/ec.cpp src/base58.cpp src/checksum.cpp src/WIF.cpp src/utils.cpp - src/main.cpp + ${src_main} ) target_link_libraries( ${CMAKE_PROJECT_NAME} PUBLIC ${OPENSSL_LIBRARIES} ) diff --git a/src/wasm.cpp b/src/wasm.cpp new file mode 100644 index 0000000..8c48e70 --- /dev/null +++ b/src/wasm.cpp @@ -0,0 +1,42 @@ +/** + * MIT License + * + * Copyright (c) 2019-2020 EOS Sw/eden + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include +#include +#include +#include +#include "WIF.h" +#include "ec.h" + +emscripten::val keygen(void) { + struct ec_keypair pair; + std::string ret = ""; + ec_generate_key(&pair); + + ret = wif_pub_encode(pair.pub) + ":" + wif_priv_encode(pair.secret); + return emscripten::val(ret); +} + +EMSCRIPTEN_BINDINGS(eosiokeygen) { + emscripten::function("eosio_keygen", &keygen); +}