diff --git a/.gitignore b/.gitignore index 85e2c4e..8472b35 100644 --- a/.gitignore +++ b/.gitignore @@ -52,9 +52,6 @@ !*.ASM !*.qml !*.qmlproject -!*.rst -!*.md -!Makefile # !*.jar @@ -86,7 +83,6 @@ # Don't ignore scripts !*.sh -!*.bat # Don't ignore ssl !*.pem @@ -146,13 +142,6 @@ moc_*.cpp -# Ignore docs build -**/docs/build/* - -# Ignore JetBrain IDEs -**/.idea/ - # Ignore CMake files CMakeCache.txt /CMakeFiles/ - diff --git a/CMakeLists.txt b/CMakeLists.txt index 286db25..46ed212 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,145 +1,124 @@ cmake_minimum_required(VERSION 3.16) -project(UnoSemuxLightCoreWasm - VERSION 0.1.0 - DESCRIPTION "C++ common utilities and types library" - LANGUAGES CXX) - -set(CMAKE_VERBOSE_MAKEFILE ON) -set(CMAKE_BUILD_PARALLEL_LEVEL 3) - -set(CMAKE_SYSTEM_NAME Emscripten) -set(CMAKE_SYSTEM_PROCESSOR wasm32) -set(CMAKE_BUILD_TYPE Release) - -set(EMSCRIPTEN_ROOT $ENV{EMSDK}/upstream/emscripten) -set(CMAKE_TOOLCHAIN_FILE ${EMSCRIPTEN_ROOT}/cmake/Modules/Platform/Emscripten.cmake) -set(CMAKE_CXX_COMPILER em++) -set(CMAKE_C_COMPILER emcc) -set(CMAKE_CXX_STANDARD 20) +set(PROJECT_NAME UnoSemuxLightCoreWasm) +set(PROJECT_VERSION 0.1.1) +set(PROJECT_DESCRIPTION "UnoSemuxLightCoreWasm") +set(PROJECT_NAME_DEFINE UNOSEMUXLIGHTCOREWASM_LIBRARY) + +#set(CMAKE_VERBOSE_MAKEFILE ON) +set(CMAKE_BUILD_PARALLEL_LEVEL 1) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_C_FLAGS_RELEASE "" CACHE STRING "Uno-labs-overridden CMAKE_C_FLAGS_RELEASE" FORCE) -set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "" CACHE STRING "Uno-labs-overridden CMAKE_SHARED_LINKER_FLAGS_RELEASE" FORCE) -set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "" CACHE STRING "Uno-labs-overridden CMAKE_SHARED_LINKER_FLAGS_RELEASE" FORCE) -set(CMAKE_EXE_LINKER_FLAGS_RELEASE "" CACHE STRING "Uno-labs-overridden CMAKE_SHARED_LINKER_FLAGS_RELEASE" FORCE) -set(CMAKE_CXX_FLAGS_RELEASE "" CACHE STRING "Uno-labs-overridden CMAKE_CXX_FLAGS_RELEASE" FORCE) - -string(JOIN " " COMPILE_FLAGS - -std=gnu++20 - -O3 - - -s WASM=1 - -s ALLOW_MEMORY_GROWTH=1 - -s DISABLE_EXCEPTION_CATCHING=0 - - -fexceptions - -fvisibility=hidden - -fvisibility-inlines-hidden - -ffunction-sections - -fdata-sections - -fstrict-aliasing - -fstack-clash-protection - - -Wall - -Wextra - -Wdouble-promotion - -Wswitch-default - -Wswitch-enum - -Wuninitialized - -Wstrict-aliasing - -Wfloat-equal - -Wshadow - -Wplacement-new - -Wcast-align - -Wconversion - -Wlogical-op - -Wduplicated-cond - -Wduplicated-branches - -Wrestrict - -Wnull-dereference - -Wno-terminate - -Wno-unknown-warning-option - -Wno-unused-command-line-argument - -Wno-comment +# Find all *.cpp and *.hpp files in project +file (GLOB_RECURSE SOURCES *.cpp) +file (GLOB_RECURSE INCLUDES *.hpp) + +if (BUILD_RELEASE_WASM32) + set(NAME_OS Browser) + set(NAME_ARC wasm32) + set(CMAKE_BUILD_TYPE Release) + set(CMAKE_CXX_COMPILER em++) + set(CMAKE_C_COMPILER emcc) + set(EMSCRIPTEN_ROOT $ENV{EMSDK}/upstream/emscripten) + set(CMAKE_TOOLCHAIN_FILE ${EMSCRIPTEN_ROOT}/cmake/Modules/Platform/Emscripten.cmake) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffunction-sections -fdata-sections -fexceptions -fstrict-aliasing -fstack-clash-protection") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wdouble-promotion -Wswitch-default -Wswitch-enum -Wuninitialized") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wstrict-aliasing -Wfloat-equal -Wshadow -Wplacement-new -Wcast-align -Wconversion -Wlogical-op") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wduplicated-cond -Wduplicated-branches -Wrestrict -Wnull-dereference -Wno-terminate") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-warning-option -Wno-unused-command-line-argument -Wno-comment") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s ALLOW_MEMORY_GROWTH=1 -s WASM=1 -s DISABLE_EXCEPTION_CATCHING=0") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-gnu-string-literal-operator-template") + project(${PROJECT_NAME} DESCRIPTION ${PROJECT_DESCRIPTION} LANGUAGES CXX) + add_executable(${PROJECT_NAME} ${SOURCES}) + string(JOIN " " LINK_FLAGS + -s WASM=1 + -s DISABLE_EXCEPTION_CATCHING=0 + -s ERROR_ON_UNDEFINED_SYMBOLS=1 + -s EXTRA_EXPORTED_RUNTIME_METHODS=["UTF16ToString","stringToUTF16"] + -s ALLOW_MEMORY_GROWTH=1 + -s NO_EXIT_RUNTIME=0 + -O3 + -Wl + --gc-sections + --bind ) - -string(JOIN " " LINK_FLAGS - -s WASM=1 - -s DISABLE_EXCEPTION_CATCHING=0 - -s FULL_ES2=1 - -s ERROR_ON_UNDEFINED_SYMBOLS=1 - -s EXTRA_EXPORTED_RUNTIME_METHODS=["UTF16ToString","stringToUTF16"] - -s ALLOW_MEMORY_GROWTH=1 - -s NO_EXIT_RUNTIME=0 - - -O3 - -Wl - - --gc-sections - --bind + set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS ${LINK_FLAGS}) + target_link_libraries(${PROJECT_NAME} + PUBLIC + GpCore2 + utf8proc + sodium + GpCryptoCore + UnoSemuxLightCore ) - -# Find all *.cpp files in project -file (GLOB_RECURSE SOURCES *.cpp) - -add_executable(${PROJECT_NAME} ${SOURCES}) - -target_compile_definitions(${PROJECT_NAME} PRIVATE - UNOSEMUXLIGHTCOREWASM_LIBRARY - HAVE_NETINET_IN_H - _GLIBCXX_USE_NANOSLEEP - __EMSCRIPTEN__ - RELEASE_BUILD - NDEBUG +else() + message(FATAL_ERROR "Unknown build type, please set -DBUILD_RELEASE_WASM32=ON") +endif() + +string(TOUPPER ${CMAKE_BUILD_TYPE} BUILD_TYPE) + +target_compile_definitions(${PROJECT_NAME} + PRIVATE + ${BUILD_TYPE}_BUILD + ${PROJECT_NAME_DEFINE} + HAVE_NETINET_IN_H + _GLIBCXX_USE_NANOSLEEP ) -set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS ${COMPILE_FLAGS}) -set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS ${LINK_FLAGS}) - -set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/../.." CACHE PATH "..." FORCE) -set(TARGET_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin") -set(TARGET_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") +#------------------------ FILES LOCATIONS --------------------- +set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/../.." CACHE PATH "..." FORCE) +set(TARGET_LIB_DIR "${CMAKE_INSTALL_PREFIX}/bin") set(TARGET_EXT_INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/inc") -set(CMAKE_BINARY_DIR ${TARGET_BIN_DIR}) -set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}) -set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) +if (NOT EXISTS "${TARGET_EXT_INCLUDE_DIR}") + file(MAKE_DIRECTORY "${TARGET_EXT_INCLUDE_DIR}") +endif() -set(GPCORE2 GpCore2) -set(UTF8PROC utf8proc) -set(LIBSODIUM sodium) -set(GPCRYPTOCORE GpCryptoCore) -set(SEMUXLIGHTCORE UnoSemuxLightCore) +set(SP _) +set(OUT_BIN_DIR "${TARGET_LIB_DIR}/${CMAKE_BUILD_TYPE}${SP}${NAME_OS}${SP}${NAME_ARC}") +set(LIBRARY_OUTPUT_PATH ${OUT_BIN_DIR}) +#------------------------ LIBS --------------------- target_include_directories(${PROJECT_NAME} - PRIVATE - "${TARGET_EXT_INCLUDE_DIR}" - "${TARGET_EXT_INCLUDE_DIR}/${GPCORE2}" - "${TARGET_EXT_INCLUDE_DIR}/${UTF8PROC}" - "${TARGET_EXT_INCLUDE_DIR}/${LIBSODIUM}" - "${TARGET_EXT_INCLUDE_DIR}/${GPCRYPTOCORE}" - "${TARGET_EXT_INCLUDE_DIR}/${SEMUXLIGHTCORE}" + PRIVATE + "${TARGET_EXT_INCLUDE_DIR}" ) -target_link_directories(${PROJECT_NAME} - PUBLIC ${TARGET_LIB_DIR} - ) +set_property(TARGET ${PROJECT_NAME} PROPERTY VERSION ${PROJECT_VERSION}) +set_property(TARGET ${PROJECT_NAME} PROPERTY SOVERSION ${PROJECT_VERSION_MAJOR}) +set_property(TARGET ${PROJECT_NAME} PROPERTY INTERFACE_${PROJECT_NAME}_MAJOR_VERSION ${PROJECT_VERSION_MAJOR}) + +set_target_properties(${PROJECT_NAME} + PROPERTIES + OUTPUT_NAME ${PROJECT_NAME} + SUFFIX ".js" + ARCHIVE_OUTPUT_DIRECTORY ${OUT_BIN_DIR} + LIBRARY_OUTPUT_DIRECTORY ${OUT_BIN_DIR} + RUNTIME_OUTPUT_DIRECTORY ${OUT_BIN_DIR}) + +message(STATUS "[${PROJECT_NAME}]: ***************** Build mode ${BUILD_TYPE} *****************") +message(STATUS "[${PROJECT_NAME}]: Target name: " ${PROJECT_NAME}${MODE_SUFFIX} " version " ${PROJECT_VERSION}) +message(STATUS "[${PROJECT_NAME}]: Target arch: " ${NAME_ARC}) +message(STATUS "[${PROJECT_NAME}]: Target OS: " ${NAME_OS}) +message(STATUS "[${PROJECT_NAME}]: Build directory: " ${LIBRARY_OUTPUT_PATH}) +message(STATUS "[${PROJECT_NAME}]: C++ standart: " ${CMAKE_CXX_STANDARD}) +message(STATUS "[${PROJECT_NAME}]: GCC C compiler: " ${CMAKE_C_COMPILER}) +message(STATUS "[${PROJECT_NAME}]: GCC C++ compiler: " ${CMAKE_CXX_COMPILER}) +message(STATUS "[${PROJECT_NAME}]: GCC linker: " ${CMAKE_LINKER}) -target_link_libraries(${PROJECT_NAME} +target_link_directories(${PROJECT_NAME} PUBLIC - ${GPCORE2} - ${UTF8PROC} - ${LIBSODIUM} - ${GPCRYPTOCORE} - ${SEMUXLIGHTCORE} - ) - -message(STATUS "[${PROJECT_NAME}]: Target name: " ${PROJECT_NAME}) -message(STATUS "[${PROJECT_NAME}]: Target arch: " ${CMAKE_SYSTEM_PROCESSOR}) -message(STATUS "[${PROJECT_NAME}]: Target OS: " ${CMAKE_SYSTEM_NAME}) -message(STATUS "[${PROJECT_NAME}]: Build directory: " ${LIBRARY_OUTPUT_PATH}) -message(STATUS "[${PROJECT_NAME}]: C++ standart: " ${CMAKE_CXX_STANDARD}) -message(STATUS "[${PROJECT_NAME}]: GCC C compiler version: " ${CMAKE_C_COMPILER}) -message(STATUS "[${PROJECT_NAME}]: GCC C++ compiler version: " ${CMAKE_CXX_COMPILER}) + ${LIBRARY_OUTPUT_PATH} +) + +#------------------------ INSTALL --------------------- +install(DIRECTORY "${CMAKE_SOURCE_DIR}" + DESTINATION "${TARGET_EXT_INCLUDE_DIR}" + FILES_MATCHING + PATTERN "*.hpp" + PATTERN "*.h" + PATTERN "CMake*" EXCLUDE + PATTERN ".git" EXCLUDE + ) diff --git a/README.md b/README.md deleted file mode 100644 index 2393a7a..0000000 --- a/README.md +++ /dev/null @@ -1,84 +0,0 @@ -Semux light core webassembly library -==================================== - -This project is a **WebAssembly** version of the [Semux light core library](https://github.com/uno-labs/semux-light-core) -(written in C++, based on libSodium) for the ability to work with Semux cryptographic functions in the JavaScript projects. - -Look how easy it is to use: - - // Mnemonic phrase generation - var mnemonic_phrase = GetRes(Module.UnoSemuxWallet.new_mnemonic_pharase()); - console.log("New mnemonic phrase: '" + mnemonic_phrase + "'"); - - -Features --------- - -Since this project is a javascript wrapper around the corresponding C++ library, -it contains all the functions of the parent project. - -Capabilities: - -- Generation and import a mnemonic phrase -- Derivation of key pairs (HD Wallet) -- Signature and verification of messages (e.g. transactions) -- and more... - - -Installation ------------- - -To build the project, QMAKE and EMSCRIPTEN compiler are used. The build process is quite complicated, -so the compiled files are laid out in the assets section. - -Download an archive `uno_semux_light_core.tar.gz` from assets on release page of this project. -Then unpack the archive into your project folder. - -For use it in the browser project you have to import `UnoSemuxLightCoreWasm.js` into your HTML page: - - - - -Build ------ - -*Environment* - -- cmake 3.16 (for Ubuntu 18.04 nedeed [installing the latest CMake](https://graspingtech.com/upgrade-cmake/)) -- standard for the C++ - 20 -- gcc-10, g++-10 - - - sudo add-apt-repository ppa:ubuntu-toolchain-r/test #for gcc-10 g++-10 - sudo apt install cmake gcc-10 g++-10 build-essential libtool libboost-dev - - -*Workspace* - -- create folders **_build/src_** -- go into **_src_** and clone this repo -- go to the repo folder and run - - -*Dependences* - -[UnoSemuxLightCore](https://github.com/uno-labs/UnoSemuxLightCore.git) - - -*Build* - - emcmake cmake . - emmake make -j4 - - -Documentation -------------- - -The actual online version of the documentation you can find at: - -https://light-core-wasm.readthedocs.io/en/latest/ - -License -------- - -The project is licensed under the MIT license. diff --git a/UnoSemuxLightCoreWasm.pro b/UnoSemuxLightCoreWasm.pro index 21dc1a1..6c6fe50 100644 --- a/UnoSemuxLightCoreWasm.pro +++ b/UnoSemuxLightCoreWasm.pro @@ -3,7 +3,7 @@ QT -= core gui widgets TEMPLATE = app VER_MAJ = 0 VER_MIN = 1 -VER_PAT = 0 +VER_PAT = 1 CONFIG += warn_on DEFINES += UNOSEMUXLIGHTCOREWASM_LIBRARY \ HAVE_NETINET_IN_H \ @@ -28,8 +28,8 @@ compiler_gcc{ } #c++20 -CONFIG += c++2a -QMAKE_CXXFLAGS += -std=gnu++2a +CONFIG += c++20 +QMAKE_CXXFLAGS += -std=gnu++20 QMAKE_CXXFLAGS += -fvisibility=hidden -fvisibility-inlines-hidden QMAKE_CXXFLAGS += -ffunction-sections -fdata-sections -fexceptions -fstrict-aliasing -fstack-clash-protection @@ -49,7 +49,7 @@ debug_build { QMAKE_CXXFLAGS += -fsanitize=address -fsanitize=undefined -fno-sanitize=vptr LIBS += -lasan LIBS += -lubsan - BOOST_POSTFIX = _asan + #BOOST_POSTFIX = _asan } } else:release_build { message([$$PACKET_NAME]: ***************** Build mode RELEASE *****************) @@ -124,7 +124,7 @@ os_windows{ LIBS += -lsodium LIBS += -lutf8proc$$TARGET_POSTFIX -LIBS += -lGpCore$$TARGET_POSTFIX$$GP_CORE_LIB_V +LIBS += -lGpCore2$$TARGET_POSTFIX$$GP_CORE_LIB_V LIBS += -lGpCryptoCore$$TARGET_POSTFIX$$GP_CRYPTO_CORE_LIB_V LIBS += -lUnoSemuxLightCore$$TARGET_POSTFIX$$UNO_SEMUX_LIGHT_CORE_V @@ -141,8 +141,7 @@ SOURCES += \ Wallet/UnoSemuxTransactionTypeWasm.cpp \ Wallet/UnoSemuxTransactionWasm.cpp \ Wallet/UnoSemuxWalletWasm.cpp \ - WasmUtils/UnoSemuxWasmUtils.cpp \ - main.cpp + WasmUtils/UnoSemuxWasmUtils.cpp HEADERS += \ UnoSemuxLightCoreWasm_global.hpp \ diff --git a/Wallet/UnoSemuxAddrWasm.cpp b/Wallet/UnoSemuxAddrWasm.cpp index 0920488..a10eab3 100644 --- a/Wallet/UnoSemuxAddrWasm.cpp +++ b/Wallet/UnoSemuxAddrWasm.cpp @@ -104,3 +104,27 @@ EMSCRIPTEN_BINDINGS(UnoSemuxAddrWasm_bind) }; //https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html +/* +em++ +em++ + +Qt: +-c +-pipe +-O3 +-std=gnu++20 +-s ALLOW_MEMORY_GROWTH=1 +-D__EMSCRIPTEN__ + +Docker: +@CMakeFiles/UnoSemuxLightCoreWasm.dir/includes_CXX.rsp +-DNDEBUG +-O2 +-Wno-unknown-warning-option +-Wno-unused-command-line-argument +-std=gnu++2a + + + +em++ -s WASM=1 -s FULL_ES2=1 -s USE_WEBGL2=1 -s NO_EXIT_RUNTIME=0 -s ERROR_ON_UNDEFINED_SYMBOLS=1 -s EXTRA_EXPORTED_RUNTIME_METHODS=["UTF16ToString","stringToUTF16"] --bind -Wl,--gc-sections -O3 -s ALLOW_MEMORY_GROWTH=1 -o ../../../Bin_tmp/Release_Browser_wasm32/UnoSemuxLightCoreWasm.js UnoSemuxAddrWasm.o UnoSemuxNetworkTypeWasm.o UnoSemuxTransactionSignWasm.o UnoSemuxTransactionTypeWasm.o UnoSemuxTransactionWasm.o UnoSemuxWalletWasm.o UnoSemuxWasmUtils.o main.o -L./../../../Bin_tmp/Release_Browser_wasm32/ -L./../../../Bin_tmp/Release_Browser_wasm32//Plugins -lsodium -lutf8proc -lGpCore -lGpCryptoCore -lUnoSemuxLightCore +*/ diff --git a/Wallet/UnoSemuxWalletWasm.cpp b/Wallet/UnoSemuxWalletWasm.cpp index 9dc0f5b..cebbae3 100644 --- a/Wallet/UnoSemuxWalletWasm.cpp +++ b/Wallet/UnoSemuxWalletWasm.cpp @@ -76,19 +76,19 @@ emscripten::val UnoSemuxWalletWasm::delete_hd_group (const std::string aHDGroupI }); } -emscripten::val UnoSemuxWalletWasm::seserialize (const std::string aPassword) const +emscripten::val UnoSemuxWalletWasm::serialize (const std::string aPassword) const { return WasmExceptionCatcher([&]() { - return emscripten::val(iWallet.VC().SeserializeHex(aPassword)); + return emscripten::val(iWallet.VC().SerializeHex(aPassword)); }); } -emscripten::val UnoSemuxWalletWasm::deseserialize (const std::string aDataStrHex, const std::string aPassword) +emscripten::val UnoSemuxWalletWasm::deserialize (const std::string aDataStrHex, const std::string aPassword) { return WasmExceptionCatcher([&]() { - iWallet.V().DeseserializeHex(aDataStrHex, aPassword); + iWallet.V().DeserializeHex(aDataStrHex, aPassword); return emscripten::val::null(); }); } @@ -104,7 +104,7 @@ emscripten::val UnoSemuxWalletWasm::new_wallet (void) }); } -emscripten::val UnoSemuxWalletWasm::new_mnemonic_pharase (void) +emscripten::val UnoSemuxWalletWasm::new_mnemonic_phrase (void) { return WasmExceptionCatcher([&]() { @@ -124,9 +124,9 @@ EMSCRIPTEN_BINDINGS(UnoSemuxWalletWasm_bind) .function("find_address", &UnoSemux::UnoSemuxWalletWasm::find_address) .function("add_hd_group", &UnoSemux::UnoSemuxWalletWasm::add_hd_group) .function("delete_hd_group", &UnoSemux::UnoSemuxWalletWasm::delete_hd_group) - .function("seserialize", &UnoSemux::UnoSemuxWalletWasm::seserialize) - .function("deseserialize", &UnoSemux::UnoSemuxWalletWasm::deseserialize) + .function("serialize", &UnoSemux::UnoSemuxWalletWasm::serialize) + .function("deserialize", &UnoSemux::UnoSemuxWalletWasm::deserialize) .class_function("new_wallet", &UnoSemux::UnoSemuxWalletWasm::new_wallet) - .class_function("new_mnemonic_pharase", &UnoSemux::UnoSemuxWalletWasm::new_mnemonic_pharase) + .class_function("new_mnemonic_phrase", &UnoSemux::UnoSemuxWalletWasm::new_mnemonic_phrase) ; }; diff --git a/Wallet/UnoSemuxWalletWasm.hpp b/Wallet/UnoSemuxWalletWasm.hpp index 1198aaa..318fe62 100644 --- a/Wallet/UnoSemuxWalletWasm.hpp +++ b/Wallet/UnoSemuxWalletWasm.hpp @@ -22,11 +22,11 @@ class UnoSemuxWalletWasm emscripten::val find_address (const std::string aAddrStrHex); emscripten::val add_hd_group (const std::string aMnemonic, const std::string aPassword); emscripten::val delete_hd_group (const std::string aHDGroupId); - emscripten::val seserialize (const std::string aPassword) const; - emscripten::val deseserialize (const std::string aDataStrHex, const std::string aPassword); + emscripten::val serialize (const std::string aPassword) const; + emscripten::val deserialize (const std::string aDataStrHex, const std::string aPassword); static emscripten::val new_wallet (void); - static emscripten::val new_mnemonic_pharase (void); + static emscripten::val new_mnemonic_phrase (void); private: UnoSemuxWallet::SP iWallet; diff --git a/docs/Makefile b/docs/Makefile deleted file mode 100644 index 69fe55e..0000000 --- a/docs/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -# Minimal makefile for Sphinx documentation -# - -# You can set these variables from the command line. -SPHINXOPTS = -SPHINXBUILD = sphinx-build -SOURCEDIR = source -BUILDDIR = build - -# Put it first so that "make" without argument is like "make help". -help: - @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) - -.PHONY: help Makefile - -# Catch-all target: route all unknown targets to Sphinx using the new -# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). -%: Makefile - @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) \ No newline at end of file diff --git a/docs/README.md b/docs/README.md deleted file mode 100644 index 17c28f0..0000000 --- a/docs/README.md +++ /dev/null @@ -1,34 +0,0 @@ -# How to build documentation - -It is assumed that this documentation will be hosted on the website https://readthedocs.org/. -For assembly of documentation the **sphinx** generator is used (http://sphinx-doc.org). -The format of the source files is `*.rst` (**reStructuredText**) or `*.md` (**Markdown**). - -Information on installing the sphinx engine and how to assemble a project with documentation can be found at: -https://docs.readthedocs.io/en/stable/intro/getting-started-with-sphinx.html - - -**TL;DR** - -To build an HTML version of the documentation on your computer: - -```sh - $ pip install sphinx - $ pip install recommonmark - $ pip install sphinx-rtd-theme - $ cd /path/to/cloned/project - $ cd docs - $ make html -``` - -Go to `build/html` directory and open `index.html` file in your browser. - -You have also some other formats to build. Run `make help` to see those options. - - -# Documentation online - -The actual online version of the documentation you can find at: - -https://light-core-wasm.readthedocs.io/en/latest/ - diff --git a/docs/make.bat b/docs/make.bat deleted file mode 100644 index 543c6b1..0000000 --- a/docs/make.bat +++ /dev/null @@ -1,35 +0,0 @@ -@ECHO OFF - -pushd %~dp0 - -REM Command file for Sphinx documentation - -if "%SPHINXBUILD%" == "" ( - set SPHINXBUILD=sphinx-build -) -set SOURCEDIR=source -set BUILDDIR=build - -if "%1" == "" goto help - -%SPHINXBUILD% >NUL 2>NUL -if errorlevel 9009 ( - echo. - echo.The 'sphinx-build' command was not found. Make sure you have Sphinx - echo.installed, then set the SPHINXBUILD environment variable to point - echo.to the full path of the 'sphinx-build' executable. Alternatively you - echo.may add the Sphinx directory to PATH. - echo. - echo.If you don't have Sphinx installed, grab it from - echo.http://sphinx-doc.org/ - exit /b 1 -) - -%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% -goto end - -:help -%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% - -:end -popd diff --git a/docs/source/conf.py b/docs/source/conf.py deleted file mode 100644 index c04fc38..0000000 --- a/docs/source/conf.py +++ /dev/null @@ -1,196 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Configuration file for the Sphinx documentation builder. -# -# This file does only contain a selection of the most common options. For a -# full list see the documentation: -# http://www.sphinx-doc.org/en/master/config - -# -- Path setup -------------------------------------------------------------- - -# If extensions (or modules to document with autodoc) are in another directory, -# add these directories to sys.path here. If the directory is relative to the -# documentation root, use os.path.abspath to make it absolute, like shown here. -# -# import os -# import sys -# sys.path.insert(0, os.path.abspath('.')) - -import sphinx_rtd_theme - -# -- Project information ----------------------------------------------------- - -project = u'Semux Light Core Wasm' -copyright = u'2020, it_bear' -author = u'it_bear' - -# The short X.Y version -version = u'' -# The full version, including alpha/beta/rc tags -release = u'v1.0' - - -# -- General configuration --------------------------------------------------- - -# If your documentation needs a minimal Sphinx version, state it here. -# -# needs_sphinx = '1.0' - -# Add any Sphinx extension module names here, as strings. They can be -# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom -# ones. -extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.intersphinx', - 'sphinx.ext.todo', - 'sphinx.ext.coverage', - 'sphinx.ext.mathjax', - 'sphinx.ext.githubpages', - 'recommonmark', - 'sphinx_rtd_theme', -] - -# Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] - -# The suffix(es) of source filenames. -# You can specify multiple suffix as a list of string: -# -source_suffix = ['.rst', '.md'] -##source_suffix = '.rst' - -# The master toctree document. -master_doc = 'index' - -# The language for content autogenerated by Sphinx. Refer to documentation -# for a list of supported languages. -# -# This is also used if you do content translation via gettext catalogs. -# Usually you set "language" from the command line for these cases. -language = None - -# List of patterns, relative to source directory, that match files and -# directories to ignore when looking for source files. -# This pattern also affects html_static_path and html_extra_path. -exclude_patterns = [] - -# The name of the Pygments (syntax highlighting) style to use. -pygments_style = None - - -# -- Options for HTML output ------------------------------------------------- - -# The theme to use for HTML and HTML Help pages. See the documentation for -# a list of builtin themes. -# -#html_theme = 'alabaster' -html_theme = 'sphinx_rtd_theme' - -# Theme options are theme-specific and customize the look and feel of a theme -# further. For a list of options available for each theme, see the -# documentation. -# -# html_theme_options = {} - -# Add any paths that contain custom static files (such as style sheets) here, -# relative to this directory. They are copied after the builtin static files, -# so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] - -# Custom sidebar templates, must be a dictionary that maps document names -# to template names. -# -# The default sidebars (for documents that don't match any pattern) are -# defined by theme itself. Builtin themes are using these templates by -# default: ``['localtoc.html', 'relations.html', 'sourcelink.html', -# 'searchbox.html']``. -# -# html_sidebars = {} - - -# -- Options for HTMLHelp output --------------------------------------------- - -# Output file base name for HTML help builder. -htmlhelp_basename = 'SemuxLightCoreWebassemblydoc' - - -# -- Options for LaTeX output ------------------------------------------------ - -latex_elements = { - # The paper size ('letterpaper' or 'a4paper'). - # - # 'papersize': 'letterpaper', - - # The font size ('10pt', '11pt' or '12pt'). - # - # 'pointsize': '10pt', - - # Additional stuff for the LaTeX preamble. - # - # 'preamble': '', - - # Latex figure (float) alignment - # - # 'figure_align': 'htbp', -} - -# Grouping the document tree into LaTeX files. List of tuples -# (source start file, target name, title, -# author, documentclass [howto, manual, or own class]). -latex_documents = [ - (master_doc, 'SemuxLightCoreWebassembly.tex', u'Semux Light Core Webassembly Documentation', - u'it\\_bear', 'manual'), -] - - -# -- Options for manual page output ------------------------------------------ - -# One entry per manual page. List of tuples -# (source start file, name, description, authors, manual section). -man_pages = [ - (master_doc, 'semuxlightcorewebassembly', u'Semux Light Core Webassembly Documentation', - [author], 1) -] - - -# -- Options for Texinfo output ---------------------------------------------- - -# Grouping the document tree into Texinfo files. List of tuples -# (source start file, target name, title, author, -# dir menu entry, description, category) -texinfo_documents = [ - (master_doc, 'SemuxLightCoreWebassembly', u'Semux Light Core Webassembly Documentation', - author, 'SemuxLightCoreWebassembly', 'One line description of project.', - 'Miscellaneous'), -] - - -# -- Options for Epub output ------------------------------------------------- - -# Bibliographic Dublin Core info. -epub_title = project - -# The unique identifier of the text. This can be a ISBN number -# or the project homepage. -# -# epub_identifier = '' - -# A unique identification for the text. -# -# epub_uid = '' - -# A list of files that should not be packed into the epub file. -epub_exclude_files = ['search.html'] - - -# -- Extension configuration ------------------------------------------------- - -# -- Options for intersphinx extension --------------------------------------- - -# Example configuration for intersphinx: refer to the Python standard library. -intersphinx_mapping = {'https://docs.python.org/': None} - -# -- Options for todo extension ---------------------------------------------- - -# If true, `todo` and `todoList` produce output, else they produce nothing. -todo_include_todos = True diff --git a/docs/source/index.rst b/docs/source/index.rst deleted file mode 100644 index f1879ae..0000000 --- a/docs/source/index.rst +++ /dev/null @@ -1,29 +0,0 @@ -.. Semux Light Core Webassembly documentation master file, created by - sphinx-quickstart on Fri Jun 5 18:52:20 2020. - You can adapt this file completely to your liking, but it should at least - contain the root `toctree` directive. - -Welcome to Semux Light Core Webassembly's documentation! -======================================================== - -This project is a **WebAssembly** version of the -`Semux light core library `_ -(written in C++, based on `libSodium `_) -for the ability to work with Semux cryptographic functions in JavaScript projects. - -The project is hosted on GitHub - https://github.com/uno-labs/semux-light-core-wasm - -.. toctree:: - :maxdepth: 2 - :caption: Contents: - - usage/Introduction - usage/Terms - usage/Get-started - usage/Wallet - usage/Addr - usage/NetworkType - usage/Transaction - usage/TransactionSign - usage/TransactionType - diff --git a/docs/source/usage/Addr.rst b/docs/source/usage/Addr.rst deleted file mode 100644 index 01c5c17..0000000 --- a/docs/source/usage/Addr.rst +++ /dev/null @@ -1,110 +0,0 @@ -Addr class -========== - -.. js:class:: Addr - - This class is designed to work with a specific key pair (not with an :term:`HD wallet` or an :term:`HD Group`). - - -Static methods --------------- - - The class has no static methods. - - -Class methods -------------- - -.. js:method:: address() - - :returns: A ``string`` containing a :term:`Semux-address` (without leading '0x'). - - | Method to get a HEX representation of itself (aka :term:`Semux-address`). - | Example: - - .. code-block:: javascript - - //New HD address from HD group - var hdAddr = GetRes(window.semux_wallet.generate_next_hd_address(semux_hdGroupId)); - var addrStrHex = GetRes(hdAddr.address()); - console.log("New address: " + "0x" + addrStrHex); - - -.. js:method:: sign_transaction(transaction) - - :param transaction: An object of :js:class:`Transaction` class. - :returns: An ``object`` of :js:class:`TransactionSign` class. - - | Performs a signature of a :js:class:`Transaction` object. - | Example: - - .. code-block:: javascript - - var transaction = GetRes(Module.UnoSemuxTransaction.new_transaction( - network_type, - transaction_type, - String(to), - String(value), - String(fee), - String(nonce), - String(d.getTime()), - String(data), - String(gas), - String(gas_price) - )); - - console.log("Sign transaction..."); - var transaction_sign = GetRes(hdAddr.sign_transaction(transaction)); - - var transaction_hash = GetRes(transaction_sign.hash()); - console.log("Transaction hash '" + transaction_hash + "'"); - - var transaction_sign_hex_encoded = GetRes(transaction_sign.encode()); - console.log("Transaction sign hex str '" + transaction_sign_hex_encoded + "'"); - - -.. js:method:: nonce() - - :returns: A ``string`` containing the current :term:`Nonce` (string representation of SINT64 - max value is 9,223,372,036,854,775,807). - - | Method to get the current :term:`Nonce`, which was set by :js:meth:`set_nonce` method or - was incremented by :js:meth:`inc_nonce` method. - - -.. js:method:: set_nonce(nonce) - - :param string nonce: A string representation of :term:`Nonce` to set. - :returns: ``void``. - - | Set the :term:`Nonce` for this :term:`Address`. - - -.. js:method:: inc_nonce() - - :returns: A ``string`` containing the incremented :term:`Nonce`. - - | Method to increment the current :term:`Nonce`. - - -.. js:method:: private_key() - - :returns: A ``string`` HEX representation of the *private key* part of this :term:`Address`. - - | Method to get the HEX representation of the *private key* part of this :term:`Address`. - - -.. js:method:: name() - - :returns: A ``string`` containing the *name* of this :term:`Address` if any name was set by :js:meth:`set_name` method. - - | Method to set recognizable name to this :term:`Address`. - - -.. js:method:: set_name(name) - - :param string name: Any recognizable name to assign to this Address. - :returns: ``void``. - - | Set any recognizable name for this :term:`Address`. - - diff --git a/docs/source/usage/Get-started.rst b/docs/source/usage/Get-started.rst deleted file mode 100644 index 571a54c..0000000 --- a/docs/source/usage/Get-started.rst +++ /dev/null @@ -1,183 +0,0 @@ -Getting started -=============== - -Important notes ---------------- - -Some methods are **static** -and can be called without creating an object. For example: - -.. code-block:: javascript - - var result = Module.UnoSemux.(); - - -Other methods are members of objects of certain classes. -So at first you have to create an object of certain class and then to call its methods. -In fact, in this library almost always objects are created by some factory method, e.g.: - -.. code-block:: javascript - - var myObject = Module.UnoSemux.(); - var result = myObject.(); - - -All methods return a result object that always has two important fields - -``error`` and ``data``: - -- ``result.error`` - if exists, it contains an exception; -- ``result.data`` - contains result data. - -You can check for errors in the following way: - -.. code-block:: html - - - - -.. warning:: - The methods never throw exceptions related to the logic of the library. - But the system exceptions can be thrown nonetheless! - - -The arguments to the methods, which are essentially integers, are passed as string values. -The reason is that JavaScript cannot work with Big Integers. - - -Typical usage -------------- - -First of all you have to include corresponding JavaScript file into your HTML page: - -.. code-block:: html - - - - - -Mnemonic phrase generation -~~~~~~~~~~~~~~~~~~~~~~~~~~ - -.. code-block:: html - - - - -Import mnemonic phrase -~~~~~~~~~~~~~~~~~~~~~~ - -.. code-block:: html - - - - -Transaction signature -~~~~~~~~~~~~~~~~~~~~~ - -.. code-block:: html - - - diff --git a/docs/source/usage/Introduction.rst b/docs/source/usage/Introduction.rst deleted file mode 100644 index 143f42b..0000000 --- a/docs/source/usage/Introduction.rst +++ /dev/null @@ -1,58 +0,0 @@ -Introduction -============ - -This library is essentially intended to create various web versions of the Semux light :term:`HD Wallet`. -They can be used both to replace the standard wallet developed by the creators -of the `Semux core project `_, -as well as for various specialized applications (dApps) based on the Semux ecosystem. - -A `wallet` is a tool for creating asymmetric key pairs and digital signatures for transactions in the Semux network. -It should have the following main features: - -- Random mnemonic phrase generation; -- Creation or recovery an :term:`HD Account` based on a mnemonic phrase; -- Import a private key; -- Generating a random key pair (:term:`Address`); -- Deriving a sequence of key pairs (:term:`HD Addresses `) for the HD Account; -- Finding derived HD Addresses in HD Account; -- Finding :term:`non-HD Addresses ` (imported or genearated); -- Generating a message for a transaction; -- Signing transaction messages. - -In fact, a fully functional wallet must be able to perform many other functions. -Such as, for example, communication with a network node through its API -to obtain information necessary for the transaction, or -storing wallet data between user sessions in a browser. -The implementation of such advanced features is beyond the scope of this lightweight library, -designed to perform basic Semux-specific cryptographic operations in the JavaScript environment. - -The specificity of Semux algorithms is that they use cryptography on elliptic curves `Ed25519`, -and this is why you can’t use standard `Web Crypto API` present in modern browsers. -Fairly well-known `libSodium` library is most suitable for implementing the algorithms used in Semux. -This project makes heavy use of the libSodium. - -You can read more about the HD Wallets at the following links: - -- Semux Project - https://www.semux.org -- BIP-0039 - https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki -- BIP-0032 - https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki -- BIP32-Ed25519 - https://github.com/orogvany/BIP32-Ed25519-java -- SLIP-0100 - https://github.com/satoshilabs/slips/blob/master/slip-0010.md -- BIP-0044 - https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki - - -Installation ------------- - -To build the project, QMake and EMSCRIPTEN compiler are used. The build process is quite complicated, -so the compiled files are laid out in the assets at the `release section `_. - -Download an archive ``uno_semux_light_core.tar.gz`` from assets on release page of this project. -Then unpack the archive into your project folder. - -For use it in the browser project you have to import ``UnoSemuxLightCoreWasm.js`` into your HTML page: - -.. code-block:: html - - - diff --git a/docs/source/usage/NetworkType.rst b/docs/source/usage/NetworkType.rst deleted file mode 100644 index f3d7e8c..0000000 --- a/docs/source/usage/NetworkType.rst +++ /dev/null @@ -1,11 +0,0 @@ -NetworkType enum -================ - -The following constants are used to indicate the type of network: - - .. js:data:: Module.UnoSemuxNetworkType.MAINNET - .. js:data:: Module.UnoSemuxNetworkType.TESTNET - .. js:data:: Module.UnoSemuxNetworkType.DEVNET - -These constants are used when creating a :js:class:`Transaction` object. - diff --git a/docs/source/usage/Terms.rst b/docs/source/usage/Terms.rst deleted file mode 100644 index 2fcbe82..0000000 --- a/docs/source/usage/Terms.rst +++ /dev/null @@ -1,70 +0,0 @@ -Terms and Definitions -===================== - -.. glossary:: - - WebAssembly - The `WebAssembly `_ (abbreviated *Wasm*) is a software technology - that allows you to use code written in C++ in the JavaScript environment. - - - Wallet - A *wallet* is software that stores a set of key pairs of asymmetric cryptography and - allows you to perform transaction signing operations using them. - - - HD Group - An *Hierarchical Deterministic* wallet is a *wallet* that allows deriving hierarchical chains of key pairs - from the initial master seed in a deterministic way. - - - HD Wallet - The *wallet* that consists of several HD Groups. - - - HD Account - An *HD Account* is a very specific intermediate node in the hierarchy of an HD Group (defined by the Semux specification), - from which all other key pairs are derived. - - - Address - The term *Address* here means an object of the :js:class:`Addr` class, which is essentially a key pair. - - - HD Address - An *HD Address* is one of the *Addresses* in the HD Group hierarchy. - - - non-HD Address - It is single *Address* not associated with the HD Group. - It can be obtained by importing a private key or random generation. - - .. note:: - This library can simultaneously work with several non-HD addresses, - and also with several HD Groups. - - - Mnemonic phrase - *Mnemonic phrase* (or mnemonic sentence) - is a group of easy to remember words (space separated) - for the determinate generation of the master seed (and, accordingly, HD Account) for certain HD Group in HD Wallet. - - A mnemonic code or sentence is superior for human interaction compared to the handling of raw binary - or hexadecimal representations of a wallet master seed. - The sentence could be written on paper or spoken over the telephone. - - - Semux-address - Aka *"Hex address"* or *"Recipient address"*. - It's a hexadecimal string that is the *"official address"* of some wallet - to which you can, for example, transfer a certain amount of cryptocurrency. - - In fact, a *Semux-address* is obtained by taking a double hash (Blake2B-SHA256) from the public part of the *Address*. - - - Nonce - *Nonce* is a sequentially increasing and unique integer for the sender address. Max value is 9,223,372,036,854,775,807. - Used to make transactions. - If you do not know the next *Nonce* for a transaction, then you can get it by contacting the Semux node API. - - In the parameters of the methods of this library, the *Nonce* is passed as a string decimal representation. - diff --git a/docs/source/usage/Transaction.rst b/docs/source/usage/Transaction.rst deleted file mode 100644 index 4ac81d0..0000000 --- a/docs/source/usage/Transaction.rst +++ /dev/null @@ -1,92 +0,0 @@ -Transaction class -================= - -.. js:class:: Transaction - - An object of :js:class:`Transaction` class is created with factory static method :js:meth:`new_transaction` and - contains all necessary transaction parameters. - - -Static methods --------------- - -.. js:method:: new_transaction(networkType, transactionType, addressToHex, amount, fee, nonce, timestamp, dataHex, gas, gasPrice) - - :param NetworkType networkType: A type of network. - :param TransactionType transactionType: A type of transaction. - :param string addressToHex: :term:`Semux-address` in string hexadecimal form. - :param string amount: Amount of payment (integer value `in nanosem`). - :param string fee: Amount of fee (integer value `in nanosem`). - :param string nonce: A :term:`Nonce` (unique and sequential for the sender). - :param string timestamp: A timestamp of the transaction (`in milliseconds`). - :param string dataHex: Some arbitrary text data in string hexadecimal form. - :param string gas: Amount of `gas`. - :param string gasPrice: Gas price (integer value `in nanosem`). - :returns: ``object`` of :js:class:`Transaction` class. - - | Factory method for creating of :js:class:`Transaction` class object. - | Example: - - .. code-block:: javascript - - var d = new Date(); - var network_type = Module.UnoSemuxNetworkType.TESTNET; - var transaction_type = Module.UnoSemuxTransactionType.TRANSFER; - var to = "0x82c38263217817de2ef28937c7747716eb1e7228"; - var data = "0x756E6F2D6C616273206C696768742077616C6C65742064656D6F"; // "uno-labs light wallet demo" in hex form - var value = "100000000"; // nanosem - var fee = "5000000"; // nanosem - var nonce = "533"; // Actually, you have to get it from Node API - var gas = "0"; - var gas_price = "0"; // nanosem - - var transaction = GetRes(Module.UnoSemuxTransaction.new_transaction( - network_type, - transaction_type, - String(to), - String(value), - String(fee), - String(nonce), - String(d.getTime()), - String(data), - String(gas), - String(gas_price) - )); - - var transaction_sign = GetRes(hdAddr.sign_transaction(transaction)); - - var transaction_hash = GetRes(transaction_sign.hash()); - console.log("Transaction hash '" + transaction_hash + "'"); - - var transaction_sign_hex_encoded = GetRes(transaction_sign.encode()); - console.log("Transaction sign hex str '" + transaction_sign_hex_encoded + "'"); - - -Class methods -------------- - -.. js:method:: encode() - - :returns: An encoded ``string`` of :js:class:`Transaction` object. - - | Method to get an encoded representation of itself. - - - -Getters -------- - -There are also some "getters" methods in the class: - - - network_type() - - transaction_type() - - address_to() - - value() - - fee() - - nonce() - - timestamp() - - data() - - gas() - - gas_price() - - diff --git a/docs/source/usage/TransactionSign.rst b/docs/source/usage/TransactionSign.rst deleted file mode 100644 index 7182b07..0000000 --- a/docs/source/usage/TransactionSign.rst +++ /dev/null @@ -1,64 +0,0 @@ -TransactionSign class -===================== - -.. js:class:: TransactionSign - - An object of this class is not created using the ``new`` operator, - but is returned by the :js:meth:`sign_transaction` method of :js:class:`Addr` object. - - Actually, the :js:class:`TransactionSign` objects are storage for the following data: - - - encoded transaction data; - - a transaction hash (Blake2B); - - a sign of hash; - - the public key (with no prefix) of the `key pair` with which the signature was made. - - -Class methods -------------- - -.. js:method:: data() - - :returns: A ``string`` containing encoded transaction data. - - | Method to get encoded transaction data. - - -.. js:method:: hash() - - :returns: A ``string`` containing a hash (Blake2B) of the transaction data. - - | Method to get a hash of the transaction data. - - -.. js:method:: sign() - - :returns: A ``string`` containing a sign of the transaction data hash. - - | Method to get a sign of the transaction data hash. - - -.. js:method:: public_key() - - :returns: A ``string`` containing the public key. - - | Method to get the public key (with no prefix) of the `key pair` with which the signature was made. - - -.. js:method:: encode() - - :returns: A ``string`` containing encoded :js:class:`TransactionSign` object. - - | Encode all data contained in this object in order to prepare before sending to the Semux network. - | Example: - - .. code-block:: javascript - - var transaction_sign = GetRes(hdAddr.sign_transaction(transaction)); - - var transaction_hash = GetRes(transaction_sign.hash()); - console.log("Transaction hash '" + transaction_hash + "'"); - - var transaction_sign_hex_encoded = GetRes(transaction_sign.encode()); - console.log("Transaction sign hex str '" + transaction_sign_hex_encoded + "'"); - diff --git a/docs/source/usage/TransactionType.rst b/docs/source/usage/TransactionType.rst deleted file mode 100644 index 13d4568..0000000 --- a/docs/source/usage/TransactionType.rst +++ /dev/null @@ -1,15 +0,0 @@ -TransactionType enum -==================== - -The following constants are used to indicate the type of transaction: - - .. js:data:: Module.UnoSemuxTransactionType.COINBASE - .. js:data:: Module.UnoSemuxTransactionType.TRANSFER - .. js:data:: Module.UnoSemuxTransactionType.DELEGATE - .. js:data:: Module.UnoSemuxTransactionType.VOTE - .. js:data:: Module.UnoSemuxTransactionType.UNVOTE - .. js:data:: Module.UnoSemuxTransactionType.CREATE - .. js:data:: Module.UnoSemuxTransactionType.CALL - -These constants are used when creating a :js:class:`Transaction` object. - diff --git a/docs/source/usage/Wallet.rst b/docs/source/usage/Wallet.rst deleted file mode 100644 index 0575ad5..0000000 --- a/docs/source/usage/Wallet.rst +++ /dev/null @@ -1,118 +0,0 @@ -Wallet class -=============== - -.. js:class:: Wallet - - An object of this class is not created using the ``new`` operator, - but is returned by the static factory method :js:meth:`new_wallet`. - - -Static methods --------------- - -.. js:method:: new_mnemonic_phrase() - - :returns: A ``string`` containing generated :term:`Mnemonic phrase`. - - | Generates a new mnemonic phrase. - | Example: - - .. code-block:: javascript - - var mnemonic_phrase = GetRes(Module.UnoSemuxWallet.new_mnemonic_pharase()); - console.log("New mnemonic phrase '" + mnemonic_phrase + "'"); - - -.. js:method:: new_wallet() - - :returns: An ``object`` of :js:class:`Wallet` class. - - | Factory static method to create a new object of `Wallet` class. - | Example: - - .. code-block:: javascript - - if (!window.semux_wallet) - { - console.log("New wallet"); - window.semux_wallet = GetRes(Module.UnoSemuxWallet.new_wallet()); - } - - - -Class methods -------------- - -.. js:method:: add_hd_group(mnemonic, password) - - :param String mnemonic: A mnemonic phrase to import from. - :param String password: An optional password for mnemonic import. - :returns: ``sInt64`` a new Group ID. - - | Method for creating a new :term:`HD Group` in the :term:`HD Wallet`. - | Further, the returned ID is used for operations with :term:`HD Address` es. - - .. code-block:: javascript - - var semux_hdGroupId = GetRes(window.semux_wallet.add_hd_group(mnemonic, password)); - console.log("New HD group ID = " + semux_hdGroupId); - - -.. js:method:: delete_hd_group(groupID) - - :param String groupID: The :term:`HD Group` ID to delete from the :term:`HD Wallet`. - - | Method for deletion the :term:`HD Group` by given `groupID`. - - -.. js:method:: generate_next_hd_address(groupID) - - :param String groupID: The ID of the :term:`HD Group`, that is used to get the next :term:`HD Address`. - :returns: An ``object`` of :js:class:`Addr` class. - - | Method for deriving the next :term:`HD Address` for the :term:`HD Group` by given `groupID` parameter. - | Example: - - .. code-block:: javascript - - var hdAddr = GetRes(window.semux_wallet.generate_next_hd_address(semux_hdGroupId)); - - -.. js:method:: generate_random_address() - - :returns: An ``object`` of :js:class:`Addr` class. - - | Method for generating a random :term:`Address` not associated with any :term:`HD Group`. - - -.. js:method:: delete_address(hexAddress) - - :param String hexAddress: The :term:`Semux-address` representation of :term:`Address` to delete from the :term:`Wallet`. - - | Method for deletion the :term:`Address` from the :term:`Wallet` by given :term:`Semux-address`. - - -.. js:method:: find_address(hexAddress) - - :param String hexAddress: The :term:`Semux-address` representation of :term:`Address` to find in the :term:`Wallet`. - :returns: An ``object`` of :js:class:`Addr` class. - - | Method for finding and getting the ``object`` of :js:class:`Addr` class in the :term:`Wallet` by given :term:`Semux-address`. - - -.. js:method::serialize(password) - - :param String password: The password to encrypt the serialization. - :returns: A ``String`` containing the HEX serialized :term:`Wallet`. - - | Method to serialize the :term:`Wallet` with the purpose of storing it aside. - - -.. js:method::deserialize(hexSerializedWallet, password) - - :param String hexSerializedWallet: A string hex representation of the serialized wallet. - :param String password: The password to decrypt the serialized wallet. - - | Method to deserialize the :term:`Wallet` which was stored aside. - - diff --git a/main.cpp b/main.cpp deleted file mode 100644 index 08891a6..0000000 --- a/main.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include "Wallet/UnoSemuxWalletWasm.hpp" - -#include - -using namespace UnoSemux; - -int main() -{ - try - { - /*GpCryptoCore::SInit(); - - UnoSemuxAccountHD::SP semuxAccountHD = UnoSemuxAccountHD::SImportFromMnemonic("garbage banner bar limb canyon width maple alien soda grow say brass"_sv, - GpCryptoHDNetworkType::TEST_NET); - - UnoSemuxAddr::SP addr1 = semuxAccountHD.V().AddrAddNextHD(); - UnoSemuxAddr::SP addr2 = semuxAccountHD.V().AddrAddNextHD(); - UnoSemuxAddr::SP addr3 = semuxAccountHD.V().AddrAddNextHD(); - - std::cout << "addr1: " << addr1.VC().AddrStrHex() << std::endl; - std::cout << "addr2: " << addr2.VC().AddrStrHex() << std::endl; - std::cout << "addr3: " << addr3.VC().AddrStrHex() << std::endl; - - addr1.Vn().SetNonce(1); - - { - GpBytesArray addrTo = GpStringOps::SToBytes("0x82c38263217817de2ef28937c7747716eb1e7228"_sv); - GpBytesArray data; - - UnoSemuxTransaction t(UnoSemuxNetworkType::TESTNET, - UnoSemuxTransactionType::VOTE, - addrTo, - 10000000_usem, - 5000000_usem, - addr1.VCn().Nonce(), - GpDateTimeOps::SUnixTS_s(), - data, - 0_semgas, - 0_usem); - - std::cout << "Transaction: " << GpStringOps::SFromBytes(t.Encode()) << std::endl; - - UnoSemuxTransactionSign sign = addr1.VC().Sign1(t); - const GpBytesArray signBytes = sign.Encode(); - std::cout << "Signature: " << GpStringOps::SFromBytes(signBytes) << std::endl; - } - - GpCryptoCore::SClear();*/ - } catch (const std::exception& e) - { - GpExceptionsSink::SSink(e); - } catch (...) - { - GpExceptionsSink::SSinkUnknown(); - } - - return 0; -}