Semux Light Core

Savel
semux
Published in
4 min readSep 26, 2020

The UNO-labs team presents Semux Light Core, a C++ library for working with HD-accounts and transaction signatures on the Semux network. The library is an alternative solution to the main client Semux-core (written in Java) and can be used to implement light wallets, as well as to develop various services and decentralized applications (dApps).

The distinctive features of the Semux Light Core library are speed, ease of use and cross-platform functionality. The library can be compiled for various platforms (for example, x86, x86–64, ARM and ARM64) and operating systems (Linux, Windows, macOS, Android and iOS). The library is also compiled to WebAssembly, which makes it possible to use it inside the browser and in Node.js projects.

In the future, with the help of the Semux project community, we hope to get the Semux Light Core library bindings for common programming languages, such as Java, Python, Ruby, Dart, etc. This will make it possible to use a single code base in the most responsible security part (with minimal maintenance costs) of various projects in the Semux ecosystem, and will significantly reduce the entry barrier for new developers.

What is it for

The basic idea is that you can safely work with private keys and Semux accounts on your computer, laptop, smartphone or your own server, but at the same time:

  • firstly, you no longer have to install a full node and download gigabytes of blockchain for full synchronization (and as you know, the size of the blockchain does not decrease, but only grows, and imagine how much space it will take in 10–20 years);
  • secondly, you still do not risk your private keys when connecting to a node or server on the Semux network, because you only transfer already signed transactions to the network and nothing else.

Project structure

The Semux Light Core library has a modular structure and consists of the following main blocks:

1. GpCore is a low-level library that implements common C++ utilities and types, including working with memory, exception handling, debug logger, threads, etc.

2. Libsodium is a well-known cryptographic C-library that implements encryption, signing and hashing functions. The library works with safe memory and provides functions for generating unpredictable data suitable for generating secret keys.

3. Utf8proc is a library for unicode normalization.

4. GpCryptoCore is a kernel that safely implements all the cryptographic functions we need.

5. Semux Light Core is a kernel that implements work with wallets, keys and transaction signatures, taking into account the specifics of Semux.

The compilers QMake and EMSCRIPTEN are used to build the project. The build process is quite complex, so we created a docker image containing the script to build the project (https://github.com/uno-labs/UnoLabsBuild). The script automatically pulls all dependencies and builds the project for Linux and Web Assembly platforms.

Ready assemblies for various platforms and operating systems can be found in the “releases” sections in the “Semux Light Core” and “Semux Light Core Wasm” repositories.

The project is under the MIT license.

How safe is it

We tried to make the library as safe as possible by using protected memory methods and a reliable pseudo-random number generator. How important and responsible it is can be illustrated by an example from the recent past, when users of a number of bitcoin wallets faced the theft of funds from their accounts due to a vulnerability in SecureRandom.

We use safe methods, strong type checking, overflow protection and all kinds of exception handling.

However, please note that our library is currently released in alpha version and is still subject to review and rigorous testing.

Main functions of Semux Light Core

- Generation of random mnemonic phrases;
- Creating or restoring an HD account based on a mnemonic phrase;
- Importing a private key;
- Generation of addresses — random key pairs;
- Obtaining a sequence of key pairs (HD addresses) for an HD account;
- Search for derivative HD addresses in an HD account;
- Search for non-HD addresses (imported or generated);
- Forming transaction messages;
- Signing transaction messages;
- Signing any messages.

For reference: Semux uses Ed25519 elliptic curve cryptography, and Blake2B, SHA256 and RIPEMD-160 functions are used for hashing. In addition, Semux Light Core implements the bip32, bip39 and bip44 standards.

Detailed documentation is available at https://light-core-wasm.readthedocs.io/en/latest/index.html

Demo: https://testnet.semux.top/wasm/

Usage examples for C++: https://github.com/uno-labs/UnoSemuxLightCore/tree/master/Examples

Usage examples for Node.js:
- https://gist.github.com/dinc334/300186d8322c783d5283e1f969c53e66
- https://github.com/tell-1c/semux-light-core-test —tools to generate vanity SEM addresses.

You can discuss with the developers, ask questions and get advice on our server in Discord. We look forward to your feedback.

Friends, learn blockchain technology and join development at Semux!

--

--